找回密码
 立即注册
首页 业界区 安全 【Android】RuntimeShader 应用

【Android】RuntimeShader 应用

晌集涟 6 天前
1 简介

​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    androidrientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>RuntimeShader 是 Android 13(T)中新增的特性,用于逐像素渲染界面,它使用 AGSL(Android Graphics Shading Language)编写着色器代码,底层基于 Skia 图形渲染引擎。官方介绍详见 → RuntimeShader。
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    androidrientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>相较于 OpenGL ES,RuntimeShader 具有以下特点。

  • RuntimeShader 中只有片元着色器,没有顶点着色器。
  • RuntimeShader 中用户不用输入顶点数据,简化了输入操作。
  • RuntimeShader 基于 AGSL 语言,OpenGL ES 基于 GLSL 语言。
  • AGSL 中纹理坐标值域与 View 的宽高对应,GLSL 中纹理坐标一般归一化了。
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    androidrientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>本文完整资源见 → RuntimeShader应用。
2 对 View 进行二次渲染

​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    androidrientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>MainActivity.java
  1. package com.zhyan8.shaderdemo;
  2. import androidx.appcompat.app.AppCompatActivity;
  3. import android.graphics.RenderEffect;
  4. import android.graphics.RuntimeShader;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.LinearLayout;
  8. import com.zhyan8.shaderdemo.utils.ScreenUtils;
  9. import com.zhyan8.shaderdemo.utils.StringUtils;
  10. public class MainActivity extends AppCompatActivity {
  11. <?xml version="1.0" encoding="utf-8"?>
  12. <LinearLayout
  13.     xmlns:android="http://schemas.android.com/apk/res/android"
  14.     xmlns:tools="http://schemas.android.com/tools"
  15.     android:layout_width="match_parent"
  16.     android:layout_height="match_parent"
  17.     tools:context=".MainActivity"
  18.     android:orientation="vertical"
  19.     android:gravity="center"
  20.     android:background="#FFFFFF"
  21.     android:id="@+id/parent">
  22.     <TextView
  23.         android:layout_width="wrap_content"
  24.         android:layout_height="wrap_content"
  25.         android:text="Hello World"
  26.         android:textSize="60sp"
  27.         android:textColor="#669933"/>
  28. </LinearLayout>@Override
  29. <?xml version="1.0" encoding="utf-8"?>
  30. <LinearLayout
  31.     xmlns:android="http://schemas.android.com/apk/res/android"
  32.     xmlns:tools="http://schemas.android.com/tools"
  33.     android:layout_width="match_parent"
  34.     android:layout_height="match_parent"
  35.     tools:context=".MainActivity"
  36.     android:orientation="vertical"
  37.     android:gravity="center"
  38.     android:background="#FFFFFF"
  39.     android:id="@+id/parent">
  40.     <TextView
  41.         android:layout_width="wrap_content"
  42.         android:layout_height="wrap_content"
  43.         android:text="Hello World"
  44.         android:textSize="60sp"
  45.         android:textColor="#669933"/>
  46. </LinearLayout>protected void onCreate(Bundle savedInstanceState) {
  47. <?xml version="1.0" encoding="utf-8"?>
  48. <LinearLayout
  49.     xmlns:android="http://schemas.android.com/apk/res/android"
  50.     xmlns:tools="http://schemas.android.com/tools"
  51.     android:layout_width="match_parent"
  52.     android:layout_height="match_parent"
  53.     tools:context=".MainActivity"
  54.     android:orientation="vertical"
  55.     android:gravity="center"
  56.     android:background="#FFFFFF"
  57.     android:id="@+id/parent">
  58.     <TextView
  59.         android:layout_width="wrap_content"
  60.         android:layout_height="wrap_content"
  61.         android:text="Hello World"
  62.         android:textSize="60sp"
  63.         android:textColor="#669933"/>
  64. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  65. <LinearLayout
  66.     xmlns:android="http://schemas.android.com/apk/res/android"
  67.     xmlns:tools="http://schemas.android.com/tools"
  68.     android:layout_width="match_parent"
  69.     android:layout_height="match_parent"
  70.     tools:context=".MainActivity"
  71.     android:orientation="vertical"
  72.     android:gravity="center"
  73.     android:background="#FFFFFF"
  74.     android:id="@+id/parent">
  75.     <TextView
  76.         android:layout_width="wrap_content"
  77.         android:layout_height="wrap_content"
  78.         android:text="Hello World"
  79.         android:textSize="60sp"
  80.         android:textColor="#669933"/>
  81. </LinearLayout>super.onCreate(savedInstanceState);
  82. <?xml version="1.0" encoding="utf-8"?>
  83. <LinearLayout
  84.     xmlns:android="http://schemas.android.com/apk/res/android"
  85.     xmlns:tools="http://schemas.android.com/tools"
  86.     android:layout_width="match_parent"
  87.     android:layout_height="match_parent"
  88.     tools:context=".MainActivity"
  89.     android:orientation="vertical"
  90.     android:gravity="center"
  91.     android:background="#FFFFFF"
  92.     android:id="@+id/parent">
  93.     <TextView
  94.         android:layout_width="wrap_content"
  95.         android:layout_height="wrap_content"
  96.         android:text="Hello World"
  97.         android:textSize="60sp"
  98.         android:textColor="#669933"/>
  99. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  100. <LinearLayout
  101.     xmlns:android="http://schemas.android.com/apk/res/android"
  102.     xmlns:tools="http://schemas.android.com/tools"
  103.     android:layout_width="match_parent"
  104.     android:layout_height="match_parent"
  105.     tools:context=".MainActivity"
  106.     android:orientation="vertical"
  107.     android:gravity="center"
  108.     android:background="#FFFFFF"
  109.     android:id="@+id/parent">
  110.     <TextView
  111.         android:layout_width="wrap_content"
  112.         android:layout_height="wrap_content"
  113.         android:text="Hello World"
  114.         android:textSize="60sp"
  115.         android:textColor="#669933"/>
  116. </LinearLayout>setContentView(R.layout.activity_main);
  117. <?xml version="1.0" encoding="utf-8"?>
  118. <LinearLayout
  119.     xmlns:android="http://schemas.android.com/apk/res/android"
  120.     xmlns:tools="http://schemas.android.com/tools"
  121.     android:layout_width="match_parent"
  122.     android:layout_height="match_parent"
  123.     tools:context=".MainActivity"
  124.     android:orientation="vertical"
  125.     android:gravity="center"
  126.     android:background="#FFFFFF"
  127.     android:id="@+id/parent">
  128.     <TextView
  129.         android:layout_width="wrap_content"
  130.         android:layout_height="wrap_content"
  131.         android:text="Hello World"
  132.         android:textSize="60sp"
  133.         android:textColor="#669933"/>
  134. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  135. <LinearLayout
  136.     xmlns:android="http://schemas.android.com/apk/res/android"
  137.     xmlns:tools="http://schemas.android.com/tools"
  138.     android:layout_width="match_parent"
  139.     android:layout_height="match_parent"
  140.     tools:context=".MainActivity"
  141.     android:orientation="vertical"
  142.     android:gravity="center"
  143.     android:background="#FFFFFF"
  144.     android:id="@+id/parent">
  145.     <TextView
  146.         android:layout_width="wrap_content"
  147.         android:layout_height="wrap_content"
  148.         android:text="Hello World"
  149.         android:textSize="60sp"
  150.         android:textColor="#669933"/>
  151. </LinearLayout>LinearLayout parentView = findViewById(R.id.parent);
  152. <?xml version="1.0" encoding="utf-8"?>
  153. <LinearLayout
  154.     xmlns:android="http://schemas.android.com/apk/res/android"
  155.     xmlns:tools="http://schemas.android.com/tools"
  156.     android:layout_width="match_parent"
  157.     android:layout_height="match_parent"
  158.     tools:context=".MainActivity"
  159.     android:orientation="vertical"
  160.     android:gravity="center"
  161.     android:background="#FFFFFF"
  162.     android:id="@+id/parent">
  163.     <TextView
  164.         android:layout_width="wrap_content"
  165.         android:layout_height="wrap_content"
  166.         android:text="Hello World"
  167.         android:textSize="60sp"
  168.         android:textColor="#669933"/>
  169. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  170. <LinearLayout
  171.     xmlns:android="http://schemas.android.com/apk/res/android"
  172.     xmlns:tools="http://schemas.android.com/tools"
  173.     android:layout_width="match_parent"
  174.     android:layout_height="match_parent"
  175.     tools:context=".MainActivity"
  176.     android:orientation="vertical"
  177.     android:gravity="center"
  178.     android:background="#FFFFFF"
  179.     android:id="@+id/parent">
  180.     <TextView
  181.         android:layout_width="wrap_content"
  182.         android:layout_height="wrap_content"
  183.         android:text="Hello World"
  184.         android:textSize="60sp"
  185.         android:textColor="#669933"/>
  186. </LinearLayout>float[] resolution = ScreenUtils.getScreenSizeF(this);
  187. <?xml version="1.0" encoding="utf-8"?>
  188. <LinearLayout
  189.     xmlns:android="http://schemas.android.com/apk/res/android"
  190.     xmlns:tools="http://schemas.android.com/tools"
  191.     android:layout_width="match_parent"
  192.     android:layout_height="match_parent"
  193.     tools:context=".MainActivity"
  194.     android:orientation="vertical"
  195.     android:gravity="center"
  196.     android:background="#FFFFFF"
  197.     android:id="@+id/parent">
  198.     <TextView
  199.         android:layout_width="wrap_content"
  200.         android:layout_height="wrap_content"
  201.         android:text="Hello World"
  202.         android:textSize="60sp"
  203.         android:textColor="#669933"/>
  204. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  205. <LinearLayout
  206.     xmlns:android="http://schemas.android.com/apk/res/android"
  207.     xmlns:tools="http://schemas.android.com/tools"
  208.     android:layout_width="match_parent"
  209.     android:layout_height="match_parent"
  210.     tools:context=".MainActivity"
  211.     android:orientation="vertical"
  212.     android:gravity="center"
  213.     android:background="#FFFFFF"
  214.     android:id="@+id/parent">
  215.     <TextView
  216.         android:layout_width="wrap_content"
  217.         android:layout_height="wrap_content"
  218.         android:text="Hello World"
  219.         android:textSize="60sp"
  220.         android:textColor="#669933"/>
  221. </LinearLayout>applyRuntimeShader(parentView, resolution);
  222. <?xml version="1.0" encoding="utf-8"?>
  223. <LinearLayout
  224.     xmlns:android="http://schemas.android.com/apk/res/android"
  225.     xmlns:tools="http://schemas.android.com/tools"
  226.     android:layout_width="match_parent"
  227.     android:layout_height="match_parent"
  228.     tools:context=".MainActivity"
  229.     android:orientation="vertical"
  230.     android:gravity="center"
  231.     android:background="#FFFFFF"
  232.     android:id="@+id/parent">
  233.     <TextView
  234.         android:layout_width="wrap_content"
  235.         android:layout_height="wrap_content"
  236.         android:text="Hello World"
  237.         android:textSize="60sp"
  238.         android:textColor="#669933"/>
  239. </LinearLayout>}
  240. <?xml version="1.0" encoding="utf-8"?>
  241. <LinearLayout
  242.     xmlns:android="http://schemas.android.com/apk/res/android"
  243.     xmlns:tools="http://schemas.android.com/tools"
  244.     android:layout_width="match_parent"
  245.     android:layout_height="match_parent"
  246.     tools:context=".MainActivity"
  247.     android:orientation="vertical"
  248.     android:gravity="center"
  249.     android:background="#FFFFFF"
  250.     android:id="@+id/parent">
  251.     <TextView
  252.         android:layout_width="wrap_content"
  253.         android:layout_height="wrap_content"
  254.         android:text="Hello World"
  255.         android:textSize="60sp"
  256.         android:textColor="#669933"/>
  257. </LinearLayout>private void applyRuntimeShader(View view, float[] resolution) {
  258. <?xml version="1.0" encoding="utf-8"?>
  259. <LinearLayout
  260.     xmlns:android="http://schemas.android.com/apk/res/android"
  261.     xmlns:tools="http://schemas.android.com/tools"
  262.     android:layout_width="match_parent"
  263.     android:layout_height="match_parent"
  264.     tools:context=".MainActivity"
  265.     android:orientation="vertical"
  266.     android:gravity="center"
  267.     android:background="#FFFFFF"
  268.     android:id="@+id/parent">
  269.     <TextView
  270.         android:layout_width="wrap_content"
  271.         android:layout_height="wrap_content"
  272.         android:text="Hello World"
  273.         android:textSize="60sp"
  274.         android:textColor="#669933"/>
  275. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  276. <LinearLayout
  277.     xmlns:android="http://schemas.android.com/apk/res/android"
  278.     xmlns:tools="http://schemas.android.com/tools"
  279.     android:layout_width="match_parent"
  280.     android:layout_height="match_parent"
  281.     tools:context=".MainActivity"
  282.     android:orientation="vertical"
  283.     android:gravity="center"
  284.     android:background="#FFFFFF"
  285.     android:id="@+id/parent">
  286.     <TextView
  287.         android:layout_width="wrap_content"
  288.         android:layout_height="wrap_content"
  289.         android:text="Hello World"
  290.         android:textSize="60sp"
  291.         android:textColor="#669933"/>
  292. </LinearLayout>String shaderCode = StringUtils.loadString(this, "shaders/dazzling.agsl");
  293. <?xml version="1.0" encoding="utf-8"?>
  294. <LinearLayout
  295.     xmlns:android="http://schemas.android.com/apk/res/android"
  296.     xmlns:tools="http://schemas.android.com/tools"
  297.     android:layout_width="match_parent"
  298.     android:layout_height="match_parent"
  299.     tools:context=".MainActivity"
  300.     android:orientation="vertical"
  301.     android:gravity="center"
  302.     android:background="#FFFFFF"
  303.     android:id="@+id/parent">
  304.     <TextView
  305.         android:layout_width="wrap_content"
  306.         android:layout_height="wrap_content"
  307.         android:text="Hello World"
  308.         android:textSize="60sp"
  309.         android:textColor="#669933"/>
  310. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  311. <LinearLayout
  312.     xmlns:android="http://schemas.android.com/apk/res/android"
  313.     xmlns:tools="http://schemas.android.com/tools"
  314.     android:layout_width="match_parent"
  315.     android:layout_height="match_parent"
  316.     tools:context=".MainActivity"
  317.     android:orientation="vertical"
  318.     android:gravity="center"
  319.     android:background="#FFFFFF"
  320.     android:id="@+id/parent">
  321.     <TextView
  322.         android:layout_width="wrap_content"
  323.         android:layout_height="wrap_content"
  324.         android:text="Hello World"
  325.         android:textSize="60sp"
  326.         android:textColor="#669933"/>
  327. </LinearLayout>RuntimeShader shader = new RuntimeShader(shaderCode);
  328. <?xml version="1.0" encoding="utf-8"?>
  329. <LinearLayout
  330.     xmlns:android="http://schemas.android.com/apk/res/android"
  331.     xmlns:tools="http://schemas.android.com/tools"
  332.     android:layout_width="match_parent"
  333.     android:layout_height="match_parent"
  334.     tools:context=".MainActivity"
  335.     android:orientation="vertical"
  336.     android:gravity="center"
  337.     android:background="#FFFFFF"
  338.     android:id="@+id/parent">
  339.     <TextView
  340.         android:layout_width="wrap_content"
  341.         android:layout_height="wrap_content"
  342.         android:text="Hello World"
  343.         android:textSize="60sp"
  344.         android:textColor="#669933"/>
  345. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  346. <LinearLayout
  347.     xmlns:android="http://schemas.android.com/apk/res/android"
  348.     xmlns:tools="http://schemas.android.com/tools"
  349.     android:layout_width="match_parent"
  350.     android:layout_height="match_parent"
  351.     tools:context=".MainActivity"
  352.     android:orientation="vertical"
  353.     android:gravity="center"
  354.     android:background="#FFFFFF"
  355.     android:id="@+id/parent">
  356.     <TextView
  357.         android:layout_width="wrap_content"
  358.         android:layout_height="wrap_content"
  359.         android:text="Hello World"
  360.         android:textSize="60sp"
  361.         android:textColor="#669933"/>
  362. </LinearLayout>shader.setFloatUniform("u_resolution", resolution);
  363. <?xml version="1.0" encoding="utf-8"?>
  364. <LinearLayout
  365.     xmlns:android="http://schemas.android.com/apk/res/android"
  366.     xmlns:tools="http://schemas.android.com/tools"
  367.     android:layout_width="match_parent"
  368.     android:layout_height="match_parent"
  369.     tools:context=".MainActivity"
  370.     android:orientation="vertical"
  371.     android:gravity="center"
  372.     android:background="#FFFFFF"
  373.     android:id="@+id/parent">
  374.     <TextView
  375.         android:layout_width="wrap_content"
  376.         android:layout_height="wrap_content"
  377.         android:text="Hello World"
  378.         android:textSize="60sp"
  379.         android:textColor="#669933"/>
  380. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  381. <LinearLayout
  382.     xmlns:android="http://schemas.android.com/apk/res/android"
  383.     xmlns:tools="http://schemas.android.com/tools"
  384.     android:layout_width="match_parent"
  385.     android:layout_height="match_parent"
  386.     tools:context=".MainActivity"
  387.     android:orientation="vertical"
  388.     android:gravity="center"
  389.     android:background="#FFFFFF"
  390.     android:id="@+id/parent">
  391.     <TextView
  392.         android:layout_width="wrap_content"
  393.         android:layout_height="wrap_content"
  394.         android:text="Hello World"
  395.         android:textSize="60sp"
  396.         android:textColor="#669933"/>
  397. </LinearLayout>RenderEffect effect = RenderEffect.createRuntimeShaderEffect(shader, "u_texture");
  398. <?xml version="1.0" encoding="utf-8"?>
  399. <LinearLayout
  400.     xmlns:android="http://schemas.android.com/apk/res/android"
  401.     xmlns:tools="http://schemas.android.com/tools"
  402.     android:layout_width="match_parent"
  403.     android:layout_height="match_parent"
  404.     tools:context=".MainActivity"
  405.     android:orientation="vertical"
  406.     android:gravity="center"
  407.     android:background="#FFFFFF"
  408.     android:id="@+id/parent">
  409.     <TextView
  410.         android:layout_width="wrap_content"
  411.         android:layout_height="wrap_content"
  412.         android:text="Hello World"
  413.         android:textSize="60sp"
  414.         android:textColor="#669933"/>
  415. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  416. <LinearLayout
  417.     xmlns:android="http://schemas.android.com/apk/res/android"
  418.     xmlns:tools="http://schemas.android.com/tools"
  419.     android:layout_width="match_parent"
  420.     android:layout_height="match_parent"
  421.     tools:context=".MainActivity"
  422.     android:orientation="vertical"
  423.     android:gravity="center"
  424.     android:background="#FFFFFF"
  425.     android:id="@+id/parent">
  426.     <TextView
  427.         android:layout_width="wrap_content"
  428.         android:layout_height="wrap_content"
  429.         android:text="Hello World"
  430.         android:textSize="60sp"
  431.         android:textColor="#669933"/>
  432. </LinearLayout>view.setRenderEffect(effect);
  433. <?xml version="1.0" encoding="utf-8"?>
  434. <LinearLayout
  435.     xmlns:android="http://schemas.android.com/apk/res/android"
  436.     xmlns:tools="http://schemas.android.com/tools"
  437.     android:layout_width="match_parent"
  438.     android:layout_height="match_parent"
  439.     tools:context=".MainActivity"
  440.     android:orientation="vertical"
  441.     android:gravity="center"
  442.     android:background="#FFFFFF"
  443.     android:id="@+id/parent">
  444.     <TextView
  445.         android:layout_width="wrap_content"
  446.         android:layout_height="wrap_content"
  447.         android:text="Hello World"
  448.         android:textSize="60sp"
  449.         android:textColor="#669933"/>
  450. </LinearLayout>}
  451. }
复制代码
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    androidrientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>activity_main.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:gravity="center"
  10.     android:background="#FFFFFF"
  11.     android:id="@+id/parent">
  12.     <TextView
  13.         android:layout_width="wrap_content"
  14.         android:layout_height="wrap_content"
  15.         android:text="Hello World"
  16.         android:textSize="60sp"
  17.         android:textColor="#669933"/>
  18. </LinearLayout>
复制代码
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    androidrientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>dazzling.agsl
  1. uniform shader u_texture;uniform vec2 u_resolution;vec4 main(vec2 coords) {<?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:gravity="center"
  10.     android:background="#FFFFFF"
  11.     android:id="@+id/parent">
  12.     <TextView
  13.         android:layout_width="wrap_content"
  14.         android:layout_height="wrap_content"
  15.         android:text="Hello World"
  16.         android:textSize="60sp"
  17.         android:textColor="#669933"/>
  18. </LinearLayout>vec4 tex = u_texture.eval(coords);<?xml version="1.0" encoding="utf-8"?>
  19. <LinearLayout
  20.     xmlns:android="http://schemas.android.com/apk/res/android"
  21.     xmlns:tools="http://schemas.android.com/tools"
  22.     android:layout_width="match_parent"
  23.     android:layout_height="match_parent"
  24.     tools:context=".MainActivity"
  25.     android:orientation="vertical"
  26.     android:gravity="center"
  27.     android:background="#FFFFFF"
  28.     android:id="@+id/parent">
  29.     <TextView
  30.         android:layout_width="wrap_content"
  31.         android:layout_height="wrap_content"
  32.         android:text="Hello World"
  33.         android:textSize="60sp"
  34.         android:textColor="#669933"/>
  35. </LinearLayout>vec2 normUV = coords / u_resolution;<?xml version="1.0" encoding="utf-8"?>
  36. <LinearLayout
  37.     xmlns:android="http://schemas.android.com/apk/res/android"
  38.     xmlns:tools="http://schemas.android.com/tools"
  39.     android:layout_width="match_parent"
  40.     android:layout_height="match_parent"
  41.     tools:context=".MainActivity"
  42.     android:orientation="vertical"
  43.     android:gravity="center"
  44.     android:background="#FFFFFF"
  45.     android:id="@+id/parent">
  46.     <TextView
  47.         android:layout_width="wrap_content"
  48.         android:layout_height="wrap_content"
  49.         android:text="Hello World"
  50.         android:textSize="60sp"
  51.         android:textColor="#669933"/>
  52. </LinearLayout>vec3 color = tex.rgb * vec3(normUV.x, normUV.y, 0.5);<?xml version="1.0" encoding="utf-8"?>
  53. <LinearLayout
  54.     xmlns:android="http://schemas.android.com/apk/res/android"
  55.     xmlns:tools="http://schemas.android.com/tools"
  56.     android:layout_width="match_parent"
  57.     android:layout_height="match_parent"
  58.     tools:context=".MainActivity"
  59.     android:orientation="vertical"
  60.     android:gravity="center"
  61.     android:background="#FFFFFF"
  62.     android:id="@+id/parent">
  63.     <TextView
  64.         android:layout_width="wrap_content"
  65.         android:layout_height="wrap_content"
  66.         android:text="Hello World"
  67.         android:textSize="60sp"
  68.         android:textColor="#669933"/>
  69. </LinearLayout>return vec4(color, 1.0);}
复制代码
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    androidrientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>说明:coords 的值域与 View 的宽高对应,并不是归一化的坐标。
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    androidrientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>运行效果如下。
1.png

3 通过 Canvas 进行渲染

3.1 简单应用

​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    androidrientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>MainActivity.java
  1. package com.zhyan8.shaderdemo;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.view.WindowManager;import android.widget.LinearLayout;import com.zhyan8.shaderdemo.graphics.ShaderView;public class MainActivity extends AppCompatActivity {<?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:gravity="center"
  10.     android:background="#FFFFFF"
  11.     android:id="@+id/parent">
  12.     <TextView
  13.         android:layout_width="wrap_content"
  14.         android:layout_height="wrap_content"
  15.         android:text="Hello World"
  16.         android:textSize="60sp"
  17.         android:textColor="#669933"/>
  18. </LinearLayout>private ShaderView mShaderView;<?xml version="1.0" encoding="utf-8"?>
  19. <LinearLayout
  20.     xmlns:android="http://schemas.android.com/apk/res/android"
  21.     xmlns:tools="http://schemas.android.com/tools"
  22.     android:layout_width="match_parent"
  23.     android:layout_height="match_parent"
  24.     tools:context=".MainActivity"
  25.     android:orientation="vertical"
  26.     android:gravity="center"
  27.     android:background="#FFFFFF"
  28.     android:id="@+id/parent">
  29.     <TextView
  30.         android:layout_width="wrap_content"
  31.         android:layout_height="wrap_content"
  32.         android:text="Hello World"
  33.         android:textSize="60sp"
  34.         android:textColor="#669933"/>
  35. </LinearLayout>private LinearLayout mParentView;<?xml version="1.0" encoding="utf-8"?>
  36. <LinearLayout
  37.     xmlns:android="http://schemas.android.com/apk/res/android"
  38.     xmlns:tools="http://schemas.android.com/tools"
  39.     android:layout_width="match_parent"
  40.     android:layout_height="match_parent"
  41.     tools:context=".MainActivity"
  42.     android:orientation="vertical"
  43.     android:gravity="center"
  44.     android:background="#FFFFFF"
  45.     android:id="@+id/parent">
  46.     <TextView
  47.         android:layout_width="wrap_content"
  48.         android:layout_height="wrap_content"
  49.         android:text="Hello World"
  50.         android:textSize="60sp"
  51.         android:textColor="#669933"/>
  52. </LinearLayout>@Override<?xml version="1.0" encoding="utf-8"?>
  53. <LinearLayout
  54.     xmlns:android="http://schemas.android.com/apk/res/android"
  55.     xmlns:tools="http://schemas.android.com/tools"
  56.     android:layout_width="match_parent"
  57.     android:layout_height="match_parent"
  58.     tools:context=".MainActivity"
  59.     android:orientation="vertical"
  60.     android:gravity="center"
  61.     android:background="#FFFFFF"
  62.     android:id="@+id/parent">
  63.     <TextView
  64.         android:layout_width="wrap_content"
  65.         android:layout_height="wrap_content"
  66.         android:text="Hello World"
  67.         android:textSize="60sp"
  68.         android:textColor="#669933"/>
  69. </LinearLayout>protected void onCreate(Bundle savedInstanceState) {<?xml version="1.0" encoding="utf-8"?>
  70. <LinearLayout
  71.     xmlns:android="http://schemas.android.com/apk/res/android"
  72.     xmlns:tools="http://schemas.android.com/tools"
  73.     android:layout_width="match_parent"
  74.     android:layout_height="match_parent"
  75.     tools:context=".MainActivity"
  76.     android:orientation="vertical"
  77.     android:gravity="center"
  78.     android:background="#FFFFFF"
  79.     android:id="@+id/parent">
  80.     <TextView
  81.         android:layout_width="wrap_content"
  82.         android:layout_height="wrap_content"
  83.         android:text="Hello World"
  84.         android:textSize="60sp"
  85.         android:textColor="#669933"/>
  86. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  87. <LinearLayout
  88.     xmlns:android="http://schemas.android.com/apk/res/android"
  89.     xmlns:tools="http://schemas.android.com/tools"
  90.     android:layout_width="match_parent"
  91.     android:layout_height="match_parent"
  92.     tools:context=".MainActivity"
  93.     android:orientation="vertical"
  94.     android:gravity="center"
  95.     android:background="#FFFFFF"
  96.     android:id="@+id/parent">
  97.     <TextView
  98.         android:layout_width="wrap_content"
  99.         android:layout_height="wrap_content"
  100.         android:text="Hello World"
  101.         android:textSize="60sp"
  102.         android:textColor="#669933"/>
  103. </LinearLayout>super.onCreate(savedInstanceState);<?xml version="1.0" encoding="utf-8"?>
  104. <LinearLayout
  105.     xmlns:android="http://schemas.android.com/apk/res/android"
  106.     xmlns:tools="http://schemas.android.com/tools"
  107.     android:layout_width="match_parent"
  108.     android:layout_height="match_parent"
  109.     tools:context=".MainActivity"
  110.     android:orientation="vertical"
  111.     android:gravity="center"
  112.     android:background="#FFFFFF"
  113.     android:id="@+id/parent">
  114.     <TextView
  115.         android:layout_width="wrap_content"
  116.         android:layout_height="wrap_content"
  117.         android:text="Hello World"
  118.         android:textSize="60sp"
  119.         android:textColor="#669933"/>
  120. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  121. <LinearLayout
  122.     xmlns:android="http://schemas.android.com/apk/res/android"
  123.     xmlns:tools="http://schemas.android.com/tools"
  124.     android:layout_width="match_parent"
  125.     android:layout_height="match_parent"
  126.     tools:context=".MainActivity"
  127.     android:orientation="vertical"
  128.     android:gravity="center"
  129.     android:background="#FFFFFF"
  130.     android:id="@+id/parent">
  131.     <TextView
  132.         android:layout_width="wrap_content"
  133.         android:layout_height="wrap_content"
  134.         android:text="Hello World"
  135.         android:textSize="60sp"
  136.         android:textColor="#669933"/>
  137. </LinearLayout>setContentView(R.layout.activity_main);<?xml version="1.0" encoding="utf-8"?>
  138. <LinearLayout
  139.     xmlns:android="http://schemas.android.com/apk/res/android"
  140.     xmlns:tools="http://schemas.android.com/tools"
  141.     android:layout_width="match_parent"
  142.     android:layout_height="match_parent"
  143.     tools:context=".MainActivity"
  144.     android:orientation="vertical"
  145.     android:gravity="center"
  146.     android:background="#FFFFFF"
  147.     android:id="@+id/parent">
  148.     <TextView
  149.         android:layout_width="wrap_content"
  150.         android:layout_height="wrap_content"
  151.         android:text="Hello World"
  152.         android:textSize="60sp"
  153.         android:textColor="#669933"/>
  154. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  155. <LinearLayout
  156.     xmlns:android="http://schemas.android.com/apk/res/android"
  157.     xmlns:tools="http://schemas.android.com/tools"
  158.     android:layout_width="match_parent"
  159.     android:layout_height="match_parent"
  160.     tools:context=".MainActivity"
  161.     android:orientation="vertical"
  162.     android:gravity="center"
  163.     android:background="#FFFFFF"
  164.     android:id="@+id/parent">
  165.     <TextView
  166.         android:layout_width="wrap_content"
  167.         android:layout_height="wrap_content"
  168.         android:text="Hello World"
  169.         android:textSize="60sp"
  170.         android:textColor="#669933"/>
  171. </LinearLayout>mParentView = findViewById(R.id.parent);<?xml version="1.0" encoding="utf-8"?>
  172. <LinearLayout
  173.     xmlns:android="http://schemas.android.com/apk/res/android"
  174.     xmlns:tools="http://schemas.android.com/tools"
  175.     android:layout_width="match_parent"
  176.     android:layout_height="match_parent"
  177.     tools:context=".MainActivity"
  178.     android:orientation="vertical"
  179.     android:gravity="center"
  180.     android:background="#FFFFFF"
  181.     android:id="@+id/parent">
  182.     <TextView
  183.         android:layout_width="wrap_content"
  184.         android:layout_height="wrap_content"
  185.         android:text="Hello World"
  186.         android:textSize="60sp"
  187.         android:textColor="#669933"/>
  188. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  189. <LinearLayout
  190.     xmlns:android="http://schemas.android.com/apk/res/android"
  191.     xmlns:tools="http://schemas.android.com/tools"
  192.     android:layout_width="match_parent"
  193.     android:layout_height="match_parent"
  194.     tools:context=".MainActivity"
  195.     android:orientation="vertical"
  196.     android:gravity="center"
  197.     android:background="#FFFFFF"
  198.     android:id="@+id/parent">
  199.     <TextView
  200.         android:layout_width="wrap_content"
  201.         android:layout_height="wrap_content"
  202.         android:text="Hello World"
  203.         android:textSize="60sp"
  204.         android:textColor="#669933"/>
  205. </LinearLayout>addView();<?xml version="1.0" encoding="utf-8"?>
  206. <LinearLayout
  207.     xmlns:android="http://schemas.android.com/apk/res/android"
  208.     xmlns:tools="http://schemas.android.com/tools"
  209.     android:layout_width="match_parent"
  210.     android:layout_height="match_parent"
  211.     tools:context=".MainActivity"
  212.     android:orientation="vertical"
  213.     android:gravity="center"
  214.     android:background="#FFFFFF"
  215.     android:id="@+id/parent">
  216.     <TextView
  217.         android:layout_width="wrap_content"
  218.         android:layout_height="wrap_content"
  219.         android:text="Hello World"
  220.         android:textSize="60sp"
  221.         android:textColor="#669933"/>
  222. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  223. <LinearLayout
  224.     xmlns:android="http://schemas.android.com/apk/res/android"
  225.     xmlns:tools="http://schemas.android.com/tools"
  226.     android:layout_width="match_parent"
  227.     android:layout_height="match_parent"
  228.     tools:context=".MainActivity"
  229.     android:orientation="vertical"
  230.     android:gravity="center"
  231.     android:background="#FFFFFF"
  232.     android:id="@+id/parent">
  233.     <TextView
  234.         android:layout_width="wrap_content"
  235.         android:layout_height="wrap_content"
  236.         android:text="Hello World"
  237.         android:textSize="60sp"
  238.         android:textColor="#669933"/>
  239. </LinearLayout>MyRenderer renderer = new MyRenderer(this);<?xml version="1.0" encoding="utf-8"?>
  240. <LinearLayout
  241.     xmlns:android="http://schemas.android.com/apk/res/android"
  242.     xmlns:tools="http://schemas.android.com/tools"
  243.     android:layout_width="match_parent"
  244.     android:layout_height="match_parent"
  245.     tools:context=".MainActivity"
  246.     android:orientation="vertical"
  247.     android:gravity="center"
  248.     android:background="#FFFFFF"
  249.     android:id="@+id/parent">
  250.     <TextView
  251.         android:layout_width="wrap_content"
  252.         android:layout_height="wrap_content"
  253.         android:text="Hello World"
  254.         android:textSize="60sp"
  255.         android:textColor="#669933"/>
  256. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  257. <LinearLayout
  258.     xmlns:android="http://schemas.android.com/apk/res/android"
  259.     xmlns:tools="http://schemas.android.com/tools"
  260.     android:layout_width="match_parent"
  261.     android:layout_height="match_parent"
  262.     tools:context=".MainActivity"
  263.     android:orientation="vertical"
  264.     android:gravity="center"
  265.     android:background="#FFFFFF"
  266.     android:id="@+id/parent">
  267.     <TextView
  268.         android:layout_width="wrap_content"
  269.         android:layout_height="wrap_content"
  270.         android:text="Hello World"
  271.         android:textSize="60sp"
  272.         android:textColor="#669933"/>
  273. </LinearLayout>mShaderView.setRenderer(renderer);<?xml version="1.0" encoding="utf-8"?>
  274. <LinearLayout
  275.     xmlns:android="http://schemas.android.com/apk/res/android"
  276.     xmlns:tools="http://schemas.android.com/tools"
  277.     android:layout_width="match_parent"
  278.     android:layout_height="match_parent"
  279.     tools:context=".MainActivity"
  280.     android:orientation="vertical"
  281.     android:gravity="center"
  282.     android:background="#FFFFFF"
  283.     android:id="@+id/parent">
  284.     <TextView
  285.         android:layout_width="wrap_content"
  286.         android:layout_height="wrap_content"
  287.         android:text="Hello World"
  288.         android:textSize="60sp"
  289.         android:textColor="#669933"/>
  290. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  291. <LinearLayout
  292.     xmlns:android="http://schemas.android.com/apk/res/android"
  293.     xmlns:tools="http://schemas.android.com/tools"
  294.     android:layout_width="match_parent"
  295.     android:layout_height="match_parent"
  296.     tools:context=".MainActivity"
  297.     android:orientation="vertical"
  298.     android:gravity="center"
  299.     android:background="#FFFFFF"
  300.     android:id="@+id/parent">
  301.     <TextView
  302.         android:layout_width="wrap_content"
  303.         android:layout_height="wrap_content"
  304.         android:text="Hello World"
  305.         android:textSize="60sp"
  306.         android:textColor="#669933"/>
  307. </LinearLayout>mShaderView.requestRender(true);<?xml version="1.0" encoding="utf-8"?>
  308. <LinearLayout
  309.     xmlns:android="http://schemas.android.com/apk/res/android"
  310.     xmlns:tools="http://schemas.android.com/tools"
  311.     android:layout_width="match_parent"
  312.     android:layout_height="match_parent"
  313.     tools:context=".MainActivity"
  314.     android:orientation="vertical"
  315.     android:gravity="center"
  316.     android:background="#FFFFFF"
  317.     android:id="@+id/parent">
  318.     <TextView
  319.         android:layout_width="wrap_content"
  320.         android:layout_height="wrap_content"
  321.         android:text="Hello World"
  322.         android:textSize="60sp"
  323.         android:textColor="#669933"/>
  324. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  325. <LinearLayout
  326.     xmlns:android="http://schemas.android.com/apk/res/android"
  327.     xmlns:tools="http://schemas.android.com/tools"
  328.     android:layout_width="match_parent"
  329.     android:layout_height="match_parent"
  330.     tools:context=".MainActivity"
  331.     android:orientation="vertical"
  332.     android:gravity="center"
  333.     android:background="#FFFFFF"
  334.     android:id="@+id/parent">
  335.     <TextView
  336.         android:layout_width="wrap_content"
  337.         android:layout_height="wrap_content"
  338.         android:text="Hello World"
  339.         android:textSize="60sp"
  340.         android:textColor="#669933"/>
  341. </LinearLayout>private void addView() {<?xml version="1.0" encoding="utf-8"?>
  342. <LinearLayout
  343.     xmlns:android="http://schemas.android.com/apk/res/android"
  344.     xmlns:tools="http://schemas.android.com/tools"
  345.     android:layout_width="match_parent"
  346.     android:layout_height="match_parent"
  347.     tools:context=".MainActivity"
  348.     android:orientation="vertical"
  349.     android:gravity="center"
  350.     android:background="#FFFFFF"
  351.     android:id="@+id/parent">
  352.     <TextView
  353.         android:layout_width="wrap_content"
  354.         android:layout_height="wrap_content"
  355.         android:text="Hello World"
  356.         android:textSize="60sp"
  357.         android:textColor="#669933"/>
  358. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  359. <LinearLayout
  360.     xmlns:android="http://schemas.android.com/apk/res/android"
  361.     xmlns:tools="http://schemas.android.com/tools"
  362.     android:layout_width="match_parent"
  363.     android:layout_height="match_parent"
  364.     tools:context=".MainActivity"
  365.     android:orientation="vertical"
  366.     android:gravity="center"
  367.     android:background="#FFFFFF"
  368.     android:id="@+id/parent">
  369.     <TextView
  370.         android:layout_width="wrap_content"
  371.         android:layout_height="wrap_content"
  372.         android:text="Hello World"
  373.         android:textSize="60sp"
  374.         android:textColor="#669933"/>
  375. </LinearLayout>mShaderView = new ShaderView(this);<?xml version="1.0" encoding="utf-8"?>
  376. <LinearLayout
  377.     xmlns:android="http://schemas.android.com/apk/res/android"
  378.     xmlns:tools="http://schemas.android.com/tools"
  379.     android:layout_width="match_parent"
  380.     android:layout_height="match_parent"
  381.     tools:context=".MainActivity"
  382.     android:orientation="vertical"
  383.     android:gravity="center"
  384.     android:background="#FFFFFF"
  385.     android:id="@+id/parent">
  386.     <TextView
  387.         android:layout_width="wrap_content"
  388.         android:layout_height="wrap_content"
  389.         android:text="Hello World"
  390.         android:textSize="60sp"
  391.         android:textColor="#669933"/>
  392. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  393. <LinearLayout
  394.     xmlns:android="http://schemas.android.com/apk/res/android"
  395.     xmlns:tools="http://schemas.android.com/tools"
  396.     android:layout_width="match_parent"
  397.     android:layout_height="match_parent"
  398.     tools:context=".MainActivity"
  399.     android:orientation="vertical"
  400.     android:gravity="center"
  401.     android:background="#FFFFFF"
  402.     android:id="@+id/parent">
  403.     <TextView
  404.         android:layout_width="wrap_content"
  405.         android:layout_height="wrap_content"
  406.         android:text="Hello World"
  407.         android:textSize="60sp"
  408.         android:textColor="#669933"/>
  409. </LinearLayout>WindowManager.LayoutParams lp = new WindowManager.LayoutParams(<?xml version="1.0" encoding="utf-8"?>
  410. <LinearLayout
  411.     xmlns:android="http://schemas.android.com/apk/res/android"
  412.     xmlns:tools="http://schemas.android.com/tools"
  413.     android:layout_width="match_parent"
  414.     android:layout_height="match_parent"
  415.     tools:context=".MainActivity"
  416.     android:orientation="vertical"
  417.     android:gravity="center"
  418.     android:background="#FFFFFF"
  419.     android:id="@+id/parent">
  420.     <TextView
  421.         android:layout_width="wrap_content"
  422.         android:layout_height="wrap_content"
  423.         android:text="Hello World"
  424.         android:textSize="60sp"
  425.         android:textColor="#669933"/>
  426. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  427. <LinearLayout
  428.     xmlns:android="http://schemas.android.com/apk/res/android"
  429.     xmlns:tools="http://schemas.android.com/tools"
  430.     android:layout_width="match_parent"
  431.     android:layout_height="match_parent"
  432.     tools:context=".MainActivity"
  433.     android:orientation="vertical"
  434.     android:gravity="center"
  435.     android:background="#FFFFFF"
  436.     android:id="@+id/parent">
  437.     <TextView
  438.         android:layout_width="wrap_content"
  439.         android:layout_height="wrap_content"
  440.         android:text="Hello World"
  441.         android:textSize="60sp"
  442.         android:textColor="#669933"/>
  443. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  444. <LinearLayout
  445.     xmlns:android="http://schemas.android.com/apk/res/android"
  446.     xmlns:tools="http://schemas.android.com/tools"
  447.     android:layout_width="match_parent"
  448.     android:layout_height="match_parent"
  449.     tools:context=".MainActivity"
  450.     android:orientation="vertical"
  451.     android:gravity="center"
  452.     android:background="#FFFFFF"
  453.     android:id="@+id/parent">
  454.     <TextView
  455.         android:layout_width="wrap_content"
  456.         android:layout_height="wrap_content"
  457.         android:text="Hello World"
  458.         android:textSize="60sp"
  459.         android:textColor="#669933"/>
  460. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  461. <LinearLayout
  462.     xmlns:android="http://schemas.android.com/apk/res/android"
  463.     xmlns:tools="http://schemas.android.com/tools"
  464.     android:layout_width="match_parent"
  465.     android:layout_height="match_parent"
  466.     tools:context=".MainActivity"
  467.     android:orientation="vertical"
  468.     android:gravity="center"
  469.     android:background="#FFFFFF"
  470.     android:id="@+id/parent">
  471.     <TextView
  472.         android:layout_width="wrap_content"
  473.         android:layout_height="wrap_content"
  474.         android:text="Hello World"
  475.         android:textSize="60sp"
  476.         android:textColor="#669933"/>
  477. </LinearLayout>WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,<?xml version="1.0" encoding="utf-8"?>
  478. <LinearLayout
  479.     xmlns:android="http://schemas.android.com/apk/res/android"
  480.     xmlns:tools="http://schemas.android.com/tools"
  481.     android:layout_width="match_parent"
  482.     android:layout_height="match_parent"
  483.     tools:context=".MainActivity"
  484.     android:orientation="vertical"
  485.     android:gravity="center"
  486.     android:background="#FFFFFF"
  487.     android:id="@+id/parent">
  488.     <TextView
  489.         android:layout_width="wrap_content"
  490.         android:layout_height="wrap_content"
  491.         android:text="Hello World"
  492.         android:textSize="60sp"
  493.         android:textColor="#669933"/>
  494. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  495. <LinearLayout
  496.     xmlns:android="http://schemas.android.com/apk/res/android"
  497.     xmlns:tools="http://schemas.android.com/tools"
  498.     android:layout_width="match_parent"
  499.     android:layout_height="match_parent"
  500.     tools:context=".MainActivity"
  501.     android:orientation="vertical"
  502.     android:gravity="center"
  503.     android:background="#FFFFFF"
  504.     android:id="@+id/parent">
  505.     <TextView
  506.         android:layout_width="wrap_content"
  507.         android:layout_height="wrap_content"
  508.         android:text="Hello World"
  509.         android:textSize="60sp"
  510.         android:textColor="#669933"/>
  511. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  512. <LinearLayout
  513.     xmlns:android="http://schemas.android.com/apk/res/android"
  514.     xmlns:tools="http://schemas.android.com/tools"
  515.     android:layout_width="match_parent"
  516.     android:layout_height="match_parent"
  517.     tools:context=".MainActivity"
  518.     android:orientation="vertical"
  519.     android:gravity="center"
  520.     android:background="#FFFFFF"
  521.     android:id="@+id/parent">
  522.     <TextView
  523.         android:layout_width="wrap_content"
  524.         android:layout_height="wrap_content"
  525.         android:text="Hello World"
  526.         android:textSize="60sp"
  527.         android:textColor="#669933"/>
  528. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  529. <LinearLayout
  530.     xmlns:android="http://schemas.android.com/apk/res/android"
  531.     xmlns:tools="http://schemas.android.com/tools"
  532.     android:layout_width="match_parent"
  533.     android:layout_height="match_parent"
  534.     tools:context=".MainActivity"
  535.     android:orientation="vertical"
  536.     android:gravity="center"
  537.     android:background="#FFFFFF"
  538.     android:id="@+id/parent">
  539.     <TextView
  540.         android:layout_width="wrap_content"
  541.         android:layout_height="wrap_content"
  542.         android:text="Hello World"
  543.         android:textSize="60sp"
  544.         android:textColor="#669933"/>
  545. </LinearLayout>WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);<?xml version="1.0" encoding="utf-8"?>
  546. <LinearLayout
  547.     xmlns:android="http://schemas.android.com/apk/res/android"
  548.     xmlns:tools="http://schemas.android.com/tools"
  549.     android:layout_width="match_parent"
  550.     android:layout_height="match_parent"
  551.     tools:context=".MainActivity"
  552.     android:orientation="vertical"
  553.     android:gravity="center"
  554.     android:background="#FFFFFF"
  555.     android:id="@+id/parent">
  556.     <TextView
  557.         android:layout_width="wrap_content"
  558.         android:layout_height="wrap_content"
  559.         android:text="Hello World"
  560.         android:textSize="60sp"
  561.         android:textColor="#669933"/>
  562. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  563. <LinearLayout
  564.     xmlns:android="http://schemas.android.com/apk/res/android"
  565.     xmlns:tools="http://schemas.android.com/tools"
  566.     android:layout_width="match_parent"
  567.     android:layout_height="match_parent"
  568.     tools:context=".MainActivity"
  569.     android:orientation="vertical"
  570.     android:gravity="center"
  571.     android:background="#FFFFFF"
  572.     android:id="@+id/parent">
  573.     <TextView
  574.         android:layout_width="wrap_content"
  575.         android:layout_height="wrap_content"
  576.         android:text="Hello World"
  577.         android:textSize="60sp"
  578.         android:textColor="#669933"/>
  579. </LinearLayout>lp.width = WindowManager.LayoutParams.MATCH_PARENT;<?xml version="1.0" encoding="utf-8"?>
  580. <LinearLayout
  581.     xmlns:android="http://schemas.android.com/apk/res/android"
  582.     xmlns:tools="http://schemas.android.com/tools"
  583.     android:layout_width="match_parent"
  584.     android:layout_height="match_parent"
  585.     tools:context=".MainActivity"
  586.     android:orientation="vertical"
  587.     android:gravity="center"
  588.     android:background="#FFFFFF"
  589.     android:id="@+id/parent">
  590.     <TextView
  591.         android:layout_width="wrap_content"
  592.         android:layout_height="wrap_content"
  593.         android:text="Hello World"
  594.         android:textSize="60sp"
  595.         android:textColor="#669933"/>
  596. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  597. <LinearLayout
  598.     xmlns:android="http://schemas.android.com/apk/res/android"
  599.     xmlns:tools="http://schemas.android.com/tools"
  600.     android:layout_width="match_parent"
  601.     android:layout_height="match_parent"
  602.     tools:context=".MainActivity"
  603.     android:orientation="vertical"
  604.     android:gravity="center"
  605.     android:background="#FFFFFF"
  606.     android:id="@+id/parent">
  607.     <TextView
  608.         android:layout_width="wrap_content"
  609.         android:layout_height="wrap_content"
  610.         android:text="Hello World"
  611.         android:textSize="60sp"
  612.         android:textColor="#669933"/>
  613. </LinearLayout>lp.height = WindowManager.LayoutParams.MATCH_PARENT;<?xml version="1.0" encoding="utf-8"?>
  614. <LinearLayout
  615.     xmlns:android="http://schemas.android.com/apk/res/android"
  616.     xmlns:tools="http://schemas.android.com/tools"
  617.     android:layout_width="match_parent"
  618.     android:layout_height="match_parent"
  619.     tools:context=".MainActivity"
  620.     android:orientation="vertical"
  621.     android:gravity="center"
  622.     android:background="#FFFFFF"
  623.     android:id="@+id/parent">
  624.     <TextView
  625.         android:layout_width="wrap_content"
  626.         android:layout_height="wrap_content"
  627.         android:text="Hello World"
  628.         android:textSize="60sp"
  629.         android:textColor="#669933"/>
  630. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  631. <LinearLayout
  632.     xmlns:android="http://schemas.android.com/apk/res/android"
  633.     xmlns:tools="http://schemas.android.com/tools"
  634.     android:layout_width="match_parent"
  635.     android:layout_height="match_parent"
  636.     tools:context=".MainActivity"
  637.     android:orientation="vertical"
  638.     android:gravity="center"
  639.     android:background="#FFFFFF"
  640.     android:id="@+id/parent">
  641.     <TextView
  642.         android:layout_width="wrap_content"
  643.         android:layout_height="wrap_content"
  644.         android:text="Hello World"
  645.         android:textSize="60sp"
  646.         android:textColor="#669933"/>
  647. </LinearLayout>mParentView.addView(mShaderView, lp);<?xml version="1.0" encoding="utf-8"?>
  648. <LinearLayout
  649.     xmlns:android="http://schemas.android.com/apk/res/android"
  650.     xmlns:tools="http://schemas.android.com/tools"
  651.     android:layout_width="match_parent"
  652.     android:layout_height="match_parent"
  653.     tools:context=".MainActivity"
  654.     android:orientation="vertical"
  655.     android:gravity="center"
  656.     android:background="#FFFFFF"
  657.     android:id="@+id/parent">
  658.     <TextView
  659.         android:layout_width="wrap_content"
  660.         android:layout_height="wrap_content"
  661.         android:text="Hello World"
  662.         android:textSize="60sp"
  663.         android:textColor="#669933"/>
  664. </LinearLayout>}}
复制代码
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    androidrientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>ShaderView.java
  1. package com.zhyan8.shaderdemo.graphics;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.RuntimeShader;import android.os.Handler;import android.os.Looper;import android.view.Choreographer;import android.view.View;/** * 自定义view, 承载渲染环境作用, 类比GLSurfaceView * @author little fat sheep */public class ShaderView extends View {<?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:gravity="center"
  10.     android:background="#FFFFFF"
  11.     android:id="@+id/parent">
  12.     <TextView
  13.         android:layout_width="wrap_content"
  14.         android:layout_height="wrap_content"
  15.         android:text="Hello World"
  16.         android:textSize="60sp"
  17.         android:textColor="#669933"/>
  18. </LinearLayout>private Paint mPaint = new Paint();<?xml version="1.0" encoding="utf-8"?>
  19. <LinearLayout
  20.     xmlns:android="http://schemas.android.com/apk/res/android"
  21.     xmlns:tools="http://schemas.android.com/tools"
  22.     android:layout_width="match_parent"
  23.     android:layout_height="match_parent"
  24.     tools:context=".MainActivity"
  25.     android:orientation="vertical"
  26.     android:gravity="center"
  27.     android:background="#FFFFFF"
  28.     android:id="@+id/parent">
  29.     <TextView
  30.         android:layout_width="wrap_content"
  31.         android:layout_height="wrap_content"
  32.         android:text="Hello World"
  33.         android:textSize="60sp"
  34.         android:textColor="#669933"/>
  35. </LinearLayout>private Renderer mRenderer;<?xml version="1.0" encoding="utf-8"?>
  36. <LinearLayout
  37.     xmlns:android="http://schemas.android.com/apk/res/android"
  38.     xmlns:tools="http://schemas.android.com/tools"
  39.     android:layout_width="match_parent"
  40.     android:layout_height="match_parent"
  41.     tools:context=".MainActivity"
  42.     android:orientation="vertical"
  43.     android:gravity="center"
  44.     android:background="#FFFFFF"
  45.     android:id="@+id/parent">
  46.     <TextView
  47.         android:layout_width="wrap_content"
  48.         android:layout_height="wrap_content"
  49.         android:text="Hello World"
  50.         android:textSize="60sp"
  51.         android:textColor="#669933"/>
  52. </LinearLayout>private float[] mResolution;<?xml version="1.0" encoding="utf-8"?>
  53. <LinearLayout
  54.     xmlns:android="http://schemas.android.com/apk/res/android"
  55.     xmlns:tools="http://schemas.android.com/tools"
  56.     android:layout_width="match_parent"
  57.     android:layout_height="match_parent"
  58.     tools:context=".MainActivity"
  59.     android:orientation="vertical"
  60.     android:gravity="center"
  61.     android:background="#FFFFFF"
  62.     android:id="@+id/parent">
  63.     <TextView
  64.         android:layout_width="wrap_content"
  65.         android:layout_height="wrap_content"
  66.         android:text="Hello World"
  67.         android:textSize="60sp"
  68.         android:textColor="#669933"/>
  69. </LinearLayout>private long mStartTime = 0L;<?xml version="1.0" encoding="utf-8"?>
  70. <LinearLayout
  71.     xmlns:android="http://schemas.android.com/apk/res/android"
  72.     xmlns:tools="http://schemas.android.com/tools"
  73.     android:layout_width="match_parent"
  74.     android:layout_height="match_parent"
  75.     tools:context=".MainActivity"
  76.     android:orientation="vertical"
  77.     android:gravity="center"
  78.     android:background="#FFFFFF"
  79.     android:id="@+id/parent">
  80.     <TextView
  81.         android:layout_width="wrap_content"
  82.         android:layout_height="wrap_content"
  83.         android:text="Hello World"
  84.         android:textSize="60sp"
  85.         android:textColor="#669933"/>
  86. </LinearLayout>private long mRunTime = 0L;<?xml version="1.0" encoding="utf-8"?>
  87. <LinearLayout
  88.     xmlns:android="http://schemas.android.com/apk/res/android"
  89.     xmlns:tools="http://schemas.android.com/tools"
  90.     android:layout_width="match_parent"
  91.     android:layout_height="match_parent"
  92.     tools:context=".MainActivity"
  93.     android:orientation="vertical"
  94.     android:gravity="center"
  95.     android:background="#FFFFFF"
  96.     android:id="@+id/parent">
  97.     <TextView
  98.         android:layout_width="wrap_content"
  99.         android:layout_height="wrap_content"
  100.         android:text="Hello World"
  101.         android:textSize="60sp"
  102.         android:textColor="#669933"/>
  103. </LinearLayout>private Choreographer mChoreographer;<?xml version="1.0" encoding="utf-8"?>
  104. <LinearLayout
  105.     xmlns:android="http://schemas.android.com/apk/res/android"
  106.     xmlns:tools="http://schemas.android.com/tools"
  107.     android:layout_width="match_parent"
  108.     android:layout_height="match_parent"
  109.     tools:context=".MainActivity"
  110.     android:orientation="vertical"
  111.     android:gravity="center"
  112.     android:background="#FFFFFF"
  113.     android:id="@+id/parent">
  114.     <TextView
  115.         android:layout_width="wrap_content"
  116.         android:layout_height="wrap_content"
  117.         android:text="Hello World"
  118.         android:textSize="60sp"
  119.         android:textColor="#669933"/>
  120. </LinearLayout>private Handler mHandler;<?xml version="1.0" encoding="utf-8"?>
  121. <LinearLayout
  122.     xmlns:android="http://schemas.android.com/apk/res/android"
  123.     xmlns:tools="http://schemas.android.com/tools"
  124.     android:layout_width="match_parent"
  125.     android:layout_height="match_parent"
  126.     tools:context=".MainActivity"
  127.     android:orientation="vertical"
  128.     android:gravity="center"
  129.     android:background="#FFFFFF"
  130.     android:id="@+id/parent">
  131.     <TextView
  132.         android:layout_width="wrap_content"
  133.         android:layout_height="wrap_content"
  134.         android:text="Hello World"
  135.         android:textSize="60sp"
  136.         android:textColor="#669933"/>
  137. </LinearLayout>public ShaderView(Context context) {<?xml version="1.0" encoding="utf-8"?>
  138. <LinearLayout
  139.     xmlns:android="http://schemas.android.com/apk/res/android"
  140.     xmlns:tools="http://schemas.android.com/tools"
  141.     android:layout_width="match_parent"
  142.     android:layout_height="match_parent"
  143.     tools:context=".MainActivity"
  144.     android:orientation="vertical"
  145.     android:gravity="center"
  146.     android:background="#FFFFFF"
  147.     android:id="@+id/parent">
  148.     <TextView
  149.         android:layout_width="wrap_content"
  150.         android:layout_height="wrap_content"
  151.         android:text="Hello World"
  152.         android:textSize="60sp"
  153.         android:textColor="#669933"/>
  154. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  155. <LinearLayout
  156.     xmlns:android="http://schemas.android.com/apk/res/android"
  157.     xmlns:tools="http://schemas.android.com/tools"
  158.     android:layout_width="match_parent"
  159.     android:layout_height="match_parent"
  160.     tools:context=".MainActivity"
  161.     android:orientation="vertical"
  162.     android:gravity="center"
  163.     android:background="#FFFFFF"
  164.     android:id="@+id/parent">
  165.     <TextView
  166.         android:layout_width="wrap_content"
  167.         android:layout_height="wrap_content"
  168.         android:text="Hello World"
  169.         android:textSize="60sp"
  170.         android:textColor="#669933"/>
  171. </LinearLayout>super(context);<?xml version="1.0" encoding="utf-8"?>
  172. <LinearLayout
  173.     xmlns:android="http://schemas.android.com/apk/res/android"
  174.     xmlns:tools="http://schemas.android.com/tools"
  175.     android:layout_width="match_parent"
  176.     android:layout_height="match_parent"
  177.     tools:context=".MainActivity"
  178.     android:orientation="vertical"
  179.     android:gravity="center"
  180.     android:background="#FFFFFF"
  181.     android:id="@+id/parent">
  182.     <TextView
  183.         android:layout_width="wrap_content"
  184.         android:layout_height="wrap_content"
  185.         android:text="Hello World"
  186.         android:textSize="60sp"
  187.         android:textColor="#669933"/>
  188. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  189. <LinearLayout
  190.     xmlns:android="http://schemas.android.com/apk/res/android"
  191.     xmlns:tools="http://schemas.android.com/tools"
  192.     android:layout_width="match_parent"
  193.     android:layout_height="match_parent"
  194.     tools:context=".MainActivity"
  195.     android:orientation="vertical"
  196.     android:gravity="center"
  197.     android:background="#FFFFFF"
  198.     android:id="@+id/parent">
  199.     <TextView
  200.         android:layout_width="wrap_content"
  201.         android:layout_height="wrap_content"
  202.         android:text="Hello World"
  203.         android:textSize="60sp"
  204.         android:textColor="#669933"/>
  205. </LinearLayout>mChoreographer = Choreographer.getInstance();<?xml version="1.0" encoding="utf-8"?>
  206. <LinearLayout
  207.     xmlns:android="http://schemas.android.com/apk/res/android"
  208.     xmlns:tools="http://schemas.android.com/tools"
  209.     android:layout_width="match_parent"
  210.     android:layout_height="match_parent"
  211.     tools:context=".MainActivity"
  212.     android:orientation="vertical"
  213.     android:gravity="center"
  214.     android:background="#FFFFFF"
  215.     android:id="@+id/parent">
  216.     <TextView
  217.         android:layout_width="wrap_content"
  218.         android:layout_height="wrap_content"
  219.         android:text="Hello World"
  220.         android:textSize="60sp"
  221.         android:textColor="#669933"/>
  222. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  223. <LinearLayout
  224.     xmlns:android="http://schemas.android.com/apk/res/android"
  225.     xmlns:tools="http://schemas.android.com/tools"
  226.     android:layout_width="match_parent"
  227.     android:layout_height="match_parent"
  228.     tools:context=".MainActivity"
  229.     android:orientation="vertical"
  230.     android:gravity="center"
  231.     android:background="#FFFFFF"
  232.     android:id="@+id/parent">
  233.     <TextView
  234.         android:layout_width="wrap_content"
  235.         android:layout_height="wrap_content"
  236.         android:text="Hello World"
  237.         android:textSize="60sp"
  238.         android:textColor="#669933"/>
  239. </LinearLayout>mHandler = new Handler(Looper.getMainLooper());<?xml version="1.0" encoding="utf-8"?>
  240. <LinearLayout
  241.     xmlns:android="http://schemas.android.com/apk/res/android"
  242.     xmlns:tools="http://schemas.android.com/tools"
  243.     android:layout_width="match_parent"
  244.     android:layout_height="match_parent"
  245.     tools:context=".MainActivity"
  246.     android:orientation="vertical"
  247.     android:gravity="center"
  248.     android:background="#FFFFFF"
  249.     android:id="@+id/parent">
  250.     <TextView
  251.         android:layout_width="wrap_content"
  252.         android:layout_height="wrap_content"
  253.         android:text="Hello World"
  254.         android:textSize="60sp"
  255.         android:textColor="#669933"/>
  256. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  257. <LinearLayout
  258.     xmlns:android="http://schemas.android.com/apk/res/android"
  259.     xmlns:tools="http://schemas.android.com/tools"
  260.     android:layout_width="match_parent"
  261.     android:layout_height="match_parent"
  262.     tools:context=".MainActivity"
  263.     android:orientation="vertical"
  264.     android:gravity="center"
  265.     android:background="#FFFFFF"
  266.     android:id="@+id/parent">
  267.     <TextView
  268.         android:layout_width="wrap_content"
  269.         android:layout_height="wrap_content"
  270.         android:text="Hello World"
  271.         android:textSize="60sp"
  272.         android:textColor="#669933"/>
  273. </LinearLayout>public void setRenderer(Renderer renderer) {<?xml version="1.0" encoding="utf-8"?>
  274. <LinearLayout
  275.     xmlns:android="http://schemas.android.com/apk/res/android"
  276.     xmlns:tools="http://schemas.android.com/tools"
  277.     android:layout_width="match_parent"
  278.     android:layout_height="match_parent"
  279.     tools:context=".MainActivity"
  280.     android:orientation="vertical"
  281.     android:gravity="center"
  282.     android:background="#FFFFFF"
  283.     android:id="@+id/parent">
  284.     <TextView
  285.         android:layout_width="wrap_content"
  286.         android:layout_height="wrap_content"
  287.         android:text="Hello World"
  288.         android:textSize="60sp"
  289.         android:textColor="#669933"/>
  290. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  291. <LinearLayout
  292.     xmlns:android="http://schemas.android.com/apk/res/android"
  293.     xmlns:tools="http://schemas.android.com/tools"
  294.     android:layout_width="match_parent"
  295.     android:layout_height="match_parent"
  296.     tools:context=".MainActivity"
  297.     android:orientation="vertical"
  298.     android:gravity="center"
  299.     android:background="#FFFFFF"
  300.     android:id="@+id/parent">
  301.     <TextView
  302.         android:layout_width="wrap_content"
  303.         android:layout_height="wrap_content"
  304.         android:text="Hello World"
  305.         android:textSize="60sp"
  306.         android:textColor="#669933"/>
  307. </LinearLayout>this.mRenderer = renderer;<?xml version="1.0" encoding="utf-8"?>
  308. <LinearLayout
  309.     xmlns:android="http://schemas.android.com/apk/res/android"
  310.     xmlns:tools="http://schemas.android.com/tools"
  311.     android:layout_width="match_parent"
  312.     android:layout_height="match_parent"
  313.     tools:context=".MainActivity"
  314.     android:orientation="vertical"
  315.     android:gravity="center"
  316.     android:background="#FFFFFF"
  317.     android:id="@+id/parent">
  318.     <TextView
  319.         android:layout_width="wrap_content"
  320.         android:layout_height="wrap_content"
  321.         android:text="Hello World"
  322.         android:textSize="60sp"
  323.         android:textColor="#669933"/>
  324. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  325. <LinearLayout
  326.     xmlns:android="http://schemas.android.com/apk/res/android"
  327.     xmlns:tools="http://schemas.android.com/tools"
  328.     android:layout_width="match_parent"
  329.     android:layout_height="match_parent"
  330.     tools:context=".MainActivity"
  331.     android:orientation="vertical"
  332.     android:gravity="center"
  333.     android:background="#FFFFFF"
  334.     android:id="@+id/parent">
  335.     <TextView
  336.         android:layout_width="wrap_content"
  337.         android:layout_height="wrap_content"
  338.         android:text="Hello World"
  339.         android:textSize="60sp"
  340.         android:textColor="#669933"/>
  341. </LinearLayout>RuntimeShader shader = renderer.onSurfaceCreated();<?xml version="1.0" encoding="utf-8"?>
  342. <LinearLayout
  343.     xmlns:android="http://schemas.android.com/apk/res/android"
  344.     xmlns:tools="http://schemas.android.com/tools"
  345.     android:layout_width="match_parent"
  346.     android:layout_height="match_parent"
  347.     tools:context=".MainActivity"
  348.     android:orientation="vertical"
  349.     android:gravity="center"
  350.     android:background="#FFFFFF"
  351.     android:id="@+id/parent">
  352.     <TextView
  353.         android:layout_width="wrap_content"
  354.         android:layout_height="wrap_content"
  355.         android:text="Hello World"
  356.         android:textSize="60sp"
  357.         android:textColor="#669933"/>
  358. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  359. <LinearLayout
  360.     xmlns:android="http://schemas.android.com/apk/res/android"
  361.     xmlns:tools="http://schemas.android.com/tools"
  362.     android:layout_width="match_parent"
  363.     android:layout_height="match_parent"
  364.     tools:context=".MainActivity"
  365.     android:orientation="vertical"
  366.     android:gravity="center"
  367.     android:background="#FFFFFF"
  368.     android:id="@+id/parent">
  369.     <TextView
  370.         android:layout_width="wrap_content"
  371.         android:layout_height="wrap_content"
  372.         android:text="Hello World"
  373.         android:textSize="60sp"
  374.         android:textColor="#669933"/>
  375. </LinearLayout>mPaint.setShader(shader);<?xml version="1.0" encoding="utf-8"?>
  376. <LinearLayout
  377.     xmlns:android="http://schemas.android.com/apk/res/android"
  378.     xmlns:tools="http://schemas.android.com/tools"
  379.     android:layout_width="match_parent"
  380.     android:layout_height="match_parent"
  381.     tools:context=".MainActivity"
  382.     android:orientation="vertical"
  383.     android:gravity="center"
  384.     android:background="#FFFFFF"
  385.     android:id="@+id/parent">
  386.     <TextView
  387.         android:layout_width="wrap_content"
  388.         android:layout_height="wrap_content"
  389.         android:text="Hello World"
  390.         android:textSize="60sp"
  391.         android:textColor="#669933"/>
  392. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  393. <LinearLayout
  394.     xmlns:android="http://schemas.android.com/apk/res/android"
  395.     xmlns:tools="http://schemas.android.com/tools"
  396.     android:layout_width="match_parent"
  397.     android:layout_height="match_parent"
  398.     tools:context=".MainActivity"
  399.     android:orientation="vertical"
  400.     android:gravity="center"
  401.     android:background="#FFFFFF"
  402.     android:id="@+id/parent">
  403.     <TextView
  404.         android:layout_width="wrap_content"
  405.         android:layout_height="wrap_content"
  406.         android:text="Hello World"
  407.         android:textSize="60sp"
  408.         android:textColor="#669933"/>
  409. </LinearLayout>mStartTime = System.currentTimeMillis();<?xml version="1.0" encoding="utf-8"?>
  410. <LinearLayout
  411.     xmlns:android="http://schemas.android.com/apk/res/android"
  412.     xmlns:tools="http://schemas.android.com/tools"
  413.     android:layout_width="match_parent"
  414.     android:layout_height="match_parent"
  415.     tools:context=".MainActivity"
  416.     android:orientation="vertical"
  417.     android:gravity="center"
  418.     android:background="#FFFFFF"
  419.     android:id="@+id/parent">
  420.     <TextView
  421.         android:layout_width="wrap_content"
  422.         android:layout_height="wrap_content"
  423.         android:text="Hello World"
  424.         android:textSize="60sp"
  425.         android:textColor="#669933"/>
  426. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  427. <LinearLayout
  428.     xmlns:android="http://schemas.android.com/apk/res/android"
  429.     xmlns:tools="http://schemas.android.com/tools"
  430.     android:layout_width="match_parent"
  431.     android:layout_height="match_parent"
  432.     tools:context=".MainActivity"
  433.     android:orientation="vertical"
  434.     android:gravity="center"
  435.     android:background="#FFFFFF"
  436.     android:id="@+id/parent">
  437.     <TextView
  438.         android:layout_width="wrap_content"
  439.         android:layout_height="wrap_content"
  440.         android:text="Hello World"
  441.         android:textSize="60sp"
  442.         android:textColor="#669933"/>
  443. </LinearLayout>public void requestRender() {<?xml version="1.0" encoding="utf-8"?>
  444. <LinearLayout
  445.     xmlns:android="http://schemas.android.com/apk/res/android"
  446.     xmlns:tools="http://schemas.android.com/tools"
  447.     android:layout_width="match_parent"
  448.     android:layout_height="match_parent"
  449.     tools:context=".MainActivity"
  450.     android:orientation="vertical"
  451.     android:gravity="center"
  452.     android:background="#FFFFFF"
  453.     android:id="@+id/parent">
  454.     <TextView
  455.         android:layout_width="wrap_content"
  456.         android:layout_height="wrap_content"
  457.         android:text="Hello World"
  458.         android:textSize="60sp"
  459.         android:textColor="#669933"/>
  460. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  461. <LinearLayout
  462.     xmlns:android="http://schemas.android.com/apk/res/android"
  463.     xmlns:tools="http://schemas.android.com/tools"
  464.     android:layout_width="match_parent"
  465.     android:layout_height="match_parent"
  466.     tools:context=".MainActivity"
  467.     android:orientation="vertical"
  468.     android:gravity="center"
  469.     android:background="#FFFFFF"
  470.     android:id="@+id/parent">
  471.     <TextView
  472.         android:layout_width="wrap_content"
  473.         android:layout_height="wrap_content"
  474.         android:text="Hello World"
  475.         android:textSize="60sp"
  476.         android:textColor="#669933"/>
  477. </LinearLayout>invalidate();<?xml version="1.0" encoding="utf-8"?>
  478. <LinearLayout
  479.     xmlns:android="http://schemas.android.com/apk/res/android"
  480.     xmlns:tools="http://schemas.android.com/tools"
  481.     android:layout_width="match_parent"
  482.     android:layout_height="match_parent"
  483.     tools:context=".MainActivity"
  484.     android:orientation="vertical"
  485.     android:gravity="center"
  486.     android:background="#FFFFFF"
  487.     android:id="@+id/parent">
  488.     <TextView
  489.         android:layout_width="wrap_content"
  490.         android:layout_height="wrap_content"
  491.         android:text="Hello World"
  492.         android:textSize="60sp"
  493.         android:textColor="#669933"/>
  494. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  495. <LinearLayout
  496.     xmlns:android="http://schemas.android.com/apk/res/android"
  497.     xmlns:tools="http://schemas.android.com/tools"
  498.     android:layout_width="match_parent"
  499.     android:layout_height="match_parent"
  500.     tools:context=".MainActivity"
  501.     android:orientation="vertical"
  502.     android:gravity="center"
  503.     android:background="#FFFFFF"
  504.     android:id="@+id/parent">
  505.     <TextView
  506.         android:layout_width="wrap_content"
  507.         android:layout_height="wrap_content"
  508.         android:text="Hello World"
  509.         android:textSize="60sp"
  510.         android:textColor="#669933"/>
  511. </LinearLayout>public void requestRender(long duration) {<?xml version="1.0" encoding="utf-8"?>
  512. <LinearLayout
  513.     xmlns:android="http://schemas.android.com/apk/res/android"
  514.     xmlns:tools="http://schemas.android.com/tools"
  515.     android:layout_width="match_parent"
  516.     android:layout_height="match_parent"
  517.     tools:context=".MainActivity"
  518.     android:orientation="vertical"
  519.     android:gravity="center"
  520.     android:background="#FFFFFF"
  521.     android:id="@+id/parent">
  522.     <TextView
  523.         android:layout_width="wrap_content"
  524.         android:layout_height="wrap_content"
  525.         android:text="Hello World"
  526.         android:textSize="60sp"
  527.         android:textColor="#669933"/>
  528. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  529. <LinearLayout
  530.     xmlns:android="http://schemas.android.com/apk/res/android"
  531.     xmlns:tools="http://schemas.android.com/tools"
  532.     android:layout_width="match_parent"
  533.     android:layout_height="match_parent"
  534.     tools:context=".MainActivity"
  535.     android:orientation="vertical"
  536.     android:gravity="center"
  537.     android:background="#FFFFFF"
  538.     android:id="@+id/parent">
  539.     <TextView
  540.         android:layout_width="wrap_content"
  541.         android:layout_height="wrap_content"
  542.         android:text="Hello World"
  543.         android:textSize="60sp"
  544.         android:textColor="#669933"/>
  545. </LinearLayout>mHandler.removeCallbacksAndMessages(null);<?xml version="1.0" encoding="utf-8"?>
  546. <LinearLayout
  547.     xmlns:android="http://schemas.android.com/apk/res/android"
  548.     xmlns:tools="http://schemas.android.com/tools"
  549.     android:layout_width="match_parent"
  550.     android:layout_height="match_parent"
  551.     tools:context=".MainActivity"
  552.     android:orientation="vertical"
  553.     android:gravity="center"
  554.     android:background="#FFFFFF"
  555.     android:id="@+id/parent">
  556.     <TextView
  557.         android:layout_width="wrap_content"
  558.         android:layout_height="wrap_content"
  559.         android:text="Hello World"
  560.         android:textSize="60sp"
  561.         android:textColor="#669933"/>
  562. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  563. <LinearLayout
  564.     xmlns:android="http://schemas.android.com/apk/res/android"
  565.     xmlns:tools="http://schemas.android.com/tools"
  566.     android:layout_width="match_parent"
  567.     android:layout_height="match_parent"
  568.     tools:context=".MainActivity"
  569.     android:orientation="vertical"
  570.     android:gravity="center"
  571.     android:background="#FFFFFF"
  572.     android:id="@+id/parent">
  573.     <TextView
  574.         android:layout_width="wrap_content"
  575.         android:layout_height="wrap_content"
  576.         android:text="Hello World"
  577.         android:textSize="60sp"
  578.         android:textColor="#669933"/>
  579. </LinearLayout>mHandler.post(() -> {<?xml version="1.0" encoding="utf-8"?>
  580. <LinearLayout
  581.     xmlns:android="http://schemas.android.com/apk/res/android"
  582.     xmlns:tools="http://schemas.android.com/tools"
  583.     android:layout_width="match_parent"
  584.     android:layout_height="match_parent"
  585.     tools:context=".MainActivity"
  586.     android:orientation="vertical"
  587.     android:gravity="center"
  588.     android:background="#FFFFFF"
  589.     android:id="@+id/parent">
  590.     <TextView
  591.         android:layout_width="wrap_content"
  592.         android:layout_height="wrap_content"
  593.         android:text="Hello World"
  594.         android:textSize="60sp"
  595.         android:textColor="#669933"/>
  596. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  597. <LinearLayout
  598.     xmlns:android="http://schemas.android.com/apk/res/android"
  599.     xmlns:tools="http://schemas.android.com/tools"
  600.     android:layout_width="match_parent"
  601.     android:layout_height="match_parent"
  602.     tools:context=".MainActivity"
  603.     android:orientation="vertical"
  604.     android:gravity="center"
  605.     android:background="#FFFFFF"
  606.     android:id="@+id/parent">
  607.     <TextView
  608.         android:layout_width="wrap_content"
  609.         android:layout_height="wrap_content"
  610.         android:text="Hello World"
  611.         android:textSize="60sp"
  612.         android:textColor="#669933"/>
  613. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  614. <LinearLayout
  615.     xmlns:android="http://schemas.android.com/apk/res/android"
  616.     xmlns:tools="http://schemas.android.com/tools"
  617.     android:layout_width="match_parent"
  618.     android:layout_height="match_parent"
  619.     tools:context=".MainActivity"
  620.     android:orientation="vertical"
  621.     android:gravity="center"
  622.     android:background="#FFFFFF"
  623.     android:id="@+id/parent">
  624.     <TextView
  625.         android:layout_width="wrap_content"
  626.         android:layout_height="wrap_content"
  627.         android:text="Hello World"
  628.         android:textSize="60sp"
  629.         android:textColor="#669933"/>
  630. </LinearLayout>mChoreographer.postFrameCallback(mFrameCallback);<?xml version="1.0" encoding="utf-8"?>
  631. <LinearLayout
  632.     xmlns:android="http://schemas.android.com/apk/res/android"
  633.     xmlns:tools="http://schemas.android.com/tools"
  634.     android:layout_width="match_parent"
  635.     android:layout_height="match_parent"
  636.     tools:context=".MainActivity"
  637.     android:orientation="vertical"
  638.     android:gravity="center"
  639.     android:background="#FFFFFF"
  640.     android:id="@+id/parent">
  641.     <TextView
  642.         android:layout_width="wrap_content"
  643.         android:layout_height="wrap_content"
  644.         android:text="Hello World"
  645.         android:textSize="60sp"
  646.         android:textColor="#669933"/>
  647. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  648. <LinearLayout
  649.     xmlns:android="http://schemas.android.com/apk/res/android"
  650.     xmlns:tools="http://schemas.android.com/tools"
  651.     android:layout_width="match_parent"
  652.     android:layout_height="match_parent"
  653.     tools:context=".MainActivity"
  654.     android:orientation="vertical"
  655.     android:gravity="center"
  656.     android:background="#FFFFFF"
  657.     android:id="@+id/parent">
  658.     <TextView
  659.         android:layout_width="wrap_content"
  660.         android:layout_height="wrap_content"
  661.         android:text="Hello World"
  662.         android:textSize="60sp"
  663.         android:textColor="#669933"/>
  664. </LinearLayout>});<?xml version="1.0" encoding="utf-8"?>
  665. <LinearLayout
  666.     xmlns:android="http://schemas.android.com/apk/res/android"
  667.     xmlns:tools="http://schemas.android.com/tools"
  668.     android:layout_width="match_parent"
  669.     android:layout_height="match_parent"
  670.     tools:context=".MainActivity"
  671.     android:orientation="vertical"
  672.     android:gravity="center"
  673.     android:background="#FFFFFF"
  674.     android:id="@+id/parent">
  675.     <TextView
  676.         android:layout_width="wrap_content"
  677.         android:layout_height="wrap_content"
  678.         android:text="Hello World"
  679.         android:textSize="60sp"
  680.         android:textColor="#669933"/>
  681. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  682. <LinearLayout
  683.     xmlns:android="http://schemas.android.com/apk/res/android"
  684.     xmlns:tools="http://schemas.android.com/tools"
  685.     android:layout_width="match_parent"
  686.     android:layout_height="match_parent"
  687.     tools:context=".MainActivity"
  688.     android:orientation="vertical"
  689.     android:gravity="center"
  690.     android:background="#FFFFFF"
  691.     android:id="@+id/parent">
  692.     <TextView
  693.         android:layout_width="wrap_content"
  694.         android:layout_height="wrap_content"
  695.         android:text="Hello World"
  696.         android:textSize="60sp"
  697.         android:textColor="#669933"/>
  698. </LinearLayout>mHandler.postDelayed(() -> {<?xml version="1.0" encoding="utf-8"?>
  699. <LinearLayout
  700.     xmlns:android="http://schemas.android.com/apk/res/android"
  701.     xmlns:tools="http://schemas.android.com/tools"
  702.     android:layout_width="match_parent"
  703.     android:layout_height="match_parent"
  704.     tools:context=".MainActivity"
  705.     android:orientation="vertical"
  706.     android:gravity="center"
  707.     android:background="#FFFFFF"
  708.     android:id="@+id/parent">
  709.     <TextView
  710.         android:layout_width="wrap_content"
  711.         android:layout_height="wrap_content"
  712.         android:text="Hello World"
  713.         android:textSize="60sp"
  714.         android:textColor="#669933"/>
  715. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  716. <LinearLayout
  717.     xmlns:android="http://schemas.android.com/apk/res/android"
  718.     xmlns:tools="http://schemas.android.com/tools"
  719.     android:layout_width="match_parent"
  720.     android:layout_height="match_parent"
  721.     tools:context=".MainActivity"
  722.     android:orientation="vertical"
  723.     android:gravity="center"
  724.     android:background="#FFFFFF"
  725.     android:id="@+id/parent">
  726.     <TextView
  727.         android:layout_width="wrap_content"
  728.         android:layout_height="wrap_content"
  729.         android:text="Hello World"
  730.         android:textSize="60sp"
  731.         android:textColor="#669933"/>
  732. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  733. <LinearLayout
  734.     xmlns:android="http://schemas.android.com/apk/res/android"
  735.     xmlns:tools="http://schemas.android.com/tools"
  736.     android:layout_width="match_parent"
  737.     android:layout_height="match_parent"
  738.     tools:context=".MainActivity"
  739.     android:orientation="vertical"
  740.     android:gravity="center"
  741.     android:background="#FFFFFF"
  742.     android:id="@+id/parent">
  743.     <TextView
  744.         android:layout_width="wrap_content"
  745.         android:layout_height="wrap_content"
  746.         android:text="Hello World"
  747.         android:textSize="60sp"
  748.         android:textColor="#669933"/>
  749. </LinearLayout>mChoreographer.removeFrameCallback(mFrameCallback);<?xml version="1.0" encoding="utf-8"?>
  750. <LinearLayout
  751.     xmlns:android="http://schemas.android.com/apk/res/android"
  752.     xmlns:tools="http://schemas.android.com/tools"
  753.     android:layout_width="match_parent"
  754.     android:layout_height="match_parent"
  755.     tools:context=".MainActivity"
  756.     android:orientation="vertical"
  757.     android:gravity="center"
  758.     android:background="#FFFFFF"
  759.     android:id="@+id/parent">
  760.     <TextView
  761.         android:layout_width="wrap_content"
  762.         android:layout_height="wrap_content"
  763.         android:text="Hello World"
  764.         android:textSize="60sp"
  765.         android:textColor="#669933"/>
  766. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  767. <LinearLayout
  768.     xmlns:android="http://schemas.android.com/apk/res/android"
  769.     xmlns:tools="http://schemas.android.com/tools"
  770.     android:layout_width="match_parent"
  771.     android:layout_height="match_parent"
  772.     tools:context=".MainActivity"
  773.     android:orientation="vertical"
  774.     android:gravity="center"
  775.     android:background="#FFFFFF"
  776.     android:id="@+id/parent">
  777.     <TextView
  778.         android:layout_width="wrap_content"
  779.         android:layout_height="wrap_content"
  780.         android:text="Hello World"
  781.         android:textSize="60sp"
  782.         android:textColor="#669933"/>
  783. </LinearLayout>}, duration);<?xml version="1.0" encoding="utf-8"?>
  784. <LinearLayout
  785.     xmlns:android="http://schemas.android.com/apk/res/android"
  786.     xmlns:tools="http://schemas.android.com/tools"
  787.     android:layout_width="match_parent"
  788.     android:layout_height="match_parent"
  789.     tools:context=".MainActivity"
  790.     android:orientation="vertical"
  791.     android:gravity="center"
  792.     android:background="#FFFFFF"
  793.     android:id="@+id/parent">
  794.     <TextView
  795.         android:layout_width="wrap_content"
  796.         android:layout_height="wrap_content"
  797.         android:text="Hello World"
  798.         android:textSize="60sp"
  799.         android:textColor="#669933"/>
  800. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  801. <LinearLayout
  802.     xmlns:android="http://schemas.android.com/apk/res/android"
  803.     xmlns:tools="http://schemas.android.com/tools"
  804.     android:layout_width="match_parent"
  805.     android:layout_height="match_parent"
  806.     tools:context=".MainActivity"
  807.     android:orientation="vertical"
  808.     android:gravity="center"
  809.     android:background="#FFFFFF"
  810.     android:id="@+id/parent">
  811.     <TextView
  812.         android:layout_width="wrap_content"
  813.         android:layout_height="wrap_content"
  814.         android:text="Hello World"
  815.         android:textSize="60sp"
  816.         android:textColor="#669933"/>
  817. </LinearLayout>public void requestRender(boolean continuous) {<?xml version="1.0" encoding="utf-8"?>
  818. <LinearLayout
  819.     xmlns:android="http://schemas.android.com/apk/res/android"
  820.     xmlns:tools="http://schemas.android.com/tools"
  821.     android:layout_width="match_parent"
  822.     android:layout_height="match_parent"
  823.     tools:context=".MainActivity"
  824.     android:orientation="vertical"
  825.     android:gravity="center"
  826.     android:background="#FFFFFF"
  827.     android:id="@+id/parent">
  828.     <TextView
  829.         android:layout_width="wrap_content"
  830.         android:layout_height="wrap_content"
  831.         android:text="Hello World"
  832.         android:textSize="60sp"
  833.         android:textColor="#669933"/>
  834. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  835. <LinearLayout
  836.     xmlns:android="http://schemas.android.com/apk/res/android"
  837.     xmlns:tools="http://schemas.android.com/tools"
  838.     android:layout_width="match_parent"
  839.     android:layout_height="match_parent"
  840.     tools:context=".MainActivity"
  841.     android:orientation="vertical"
  842.     android:gravity="center"
  843.     android:background="#FFFFFF"
  844.     android:id="@+id/parent">
  845.     <TextView
  846.         android:layout_width="wrap_content"
  847.         android:layout_height="wrap_content"
  848.         android:text="Hello World"
  849.         android:textSize="60sp"
  850.         android:textColor="#669933"/>
  851. </LinearLayout>if (continuous) {<?xml version="1.0" encoding="utf-8"?>
  852. <LinearLayout
  853.     xmlns:android="http://schemas.android.com/apk/res/android"
  854.     xmlns:tools="http://schemas.android.com/tools"
  855.     android:layout_width="match_parent"
  856.     android:layout_height="match_parent"
  857.     tools:context=".MainActivity"
  858.     android:orientation="vertical"
  859.     android:gravity="center"
  860.     android:background="#FFFFFF"
  861.     android:id="@+id/parent">
  862.     <TextView
  863.         android:layout_width="wrap_content"
  864.         android:layout_height="wrap_content"
  865.         android:text="Hello World"
  866.         android:textSize="60sp"
  867.         android:textColor="#669933"/>
  868. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  869. <LinearLayout
  870.     xmlns:android="http://schemas.android.com/apk/res/android"
  871.     xmlns:tools="http://schemas.android.com/tools"
  872.     android:layout_width="match_parent"
  873.     android:layout_height="match_parent"
  874.     tools:context=".MainActivity"
  875.     android:orientation="vertical"
  876.     android:gravity="center"
  877.     android:background="#FFFFFF"
  878.     android:id="@+id/parent">
  879.     <TextView
  880.         android:layout_width="wrap_content"
  881.         android:layout_height="wrap_content"
  882.         android:text="Hello World"
  883.         android:textSize="60sp"
  884.         android:textColor="#669933"/>
  885. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  886. <LinearLayout
  887.     xmlns:android="http://schemas.android.com/apk/res/android"
  888.     xmlns:tools="http://schemas.android.com/tools"
  889.     android:layout_width="match_parent"
  890.     android:layout_height="match_parent"
  891.     tools:context=".MainActivity"
  892.     android:orientation="vertical"
  893.     android:gravity="center"
  894.     android:background="#FFFFFF"
  895.     android:id="@+id/parent">
  896.     <TextView
  897.         android:layout_width="wrap_content"
  898.         android:layout_height="wrap_content"
  899.         android:text="Hello World"
  900.         android:textSize="60sp"
  901.         android:textColor="#669933"/>
  902. </LinearLayout>mChoreographer.postFrameCallback(mFrameCallback);<?xml version="1.0" encoding="utf-8"?>
  903. <LinearLayout
  904.     xmlns:android="http://schemas.android.com/apk/res/android"
  905.     xmlns:tools="http://schemas.android.com/tools"
  906.     android:layout_width="match_parent"
  907.     android:layout_height="match_parent"
  908.     tools:context=".MainActivity"
  909.     android:orientation="vertical"
  910.     android:gravity="center"
  911.     android:background="#FFFFFF"
  912.     android:id="@+id/parent">
  913.     <TextView
  914.         android:layout_width="wrap_content"
  915.         android:layout_height="wrap_content"
  916.         android:text="Hello World"
  917.         android:textSize="60sp"
  918.         android:textColor="#669933"/>
  919. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  920. <LinearLayout
  921.     xmlns:android="http://schemas.android.com/apk/res/android"
  922.     xmlns:tools="http://schemas.android.com/tools"
  923.     android:layout_width="match_parent"
  924.     android:layout_height="match_parent"
  925.     tools:context=".MainActivity"
  926.     android:orientation="vertical"
  927.     android:gravity="center"
  928.     android:background="#FFFFFF"
  929.     android:id="@+id/parent">
  930.     <TextView
  931.         android:layout_width="wrap_content"
  932.         android:layout_height="wrap_content"
  933.         android:text="Hello World"
  934.         android:textSize="60sp"
  935.         android:textColor="#669933"/>
  936. </LinearLayout>} else {<?xml version="1.0" encoding="utf-8"?>
  937. <LinearLayout
  938.     xmlns:android="http://schemas.android.com/apk/res/android"
  939.     xmlns:tools="http://schemas.android.com/tools"
  940.     android:layout_width="match_parent"
  941.     android:layout_height="match_parent"
  942.     tools:context=".MainActivity"
  943.     android:orientation="vertical"
  944.     android:gravity="center"
  945.     android:background="#FFFFFF"
  946.     android:id="@+id/parent">
  947.     <TextView
  948.         android:layout_width="wrap_content"
  949.         android:layout_height="wrap_content"
  950.         android:text="Hello World"
  951.         android:textSize="60sp"
  952.         android:textColor="#669933"/>
  953. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  954. <LinearLayout
  955.     xmlns:android="http://schemas.android.com/apk/res/android"
  956.     xmlns:tools="http://schemas.android.com/tools"
  957.     android:layout_width="match_parent"
  958.     android:layout_height="match_parent"
  959.     tools:context=".MainActivity"
  960.     android:orientation="vertical"
  961.     android:gravity="center"
  962.     android:background="#FFFFFF"
  963.     android:id="@+id/parent">
  964.     <TextView
  965.         android:layout_width="wrap_content"
  966.         android:layout_height="wrap_content"
  967.         android:text="Hello World"
  968.         android:textSize="60sp"
  969.         android:textColor="#669933"/>
  970. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  971. <LinearLayout
  972.     xmlns:android="http://schemas.android.com/apk/res/android"
  973.     xmlns:tools="http://schemas.android.com/tools"
  974.     android:layout_width="match_parent"
  975.     android:layout_height="match_parent"
  976.     tools:context=".MainActivity"
  977.     android:orientation="vertical"
  978.     android:gravity="center"
  979.     android:background="#FFFFFF"
  980.     android:id="@+id/parent">
  981.     <TextView
  982.         android:layout_width="wrap_content"
  983.         android:layout_height="wrap_content"
  984.         android:text="Hello World"
  985.         android:textSize="60sp"
  986.         android:textColor="#669933"/>
  987. </LinearLayout>invalidate();<?xml version="1.0" encoding="utf-8"?>
  988. <LinearLayout
  989.     xmlns:android="http://schemas.android.com/apk/res/android"
  990.     xmlns:tools="http://schemas.android.com/tools"
  991.     android:layout_width="match_parent"
  992.     android:layout_height="match_parent"
  993.     tools:context=".MainActivity"
  994.     android:orientation="vertical"
  995.     android:gravity="center"
  996.     android:background="#FFFFFF"
  997.     android:id="@+id/parent">
  998.     <TextView
  999.         android:layout_width="wrap_content"
  1000.         android:layout_height="wrap_content"
  1001.         android:text="Hello World"
  1002.         android:textSize="60sp"
  1003.         android:textColor="#669933"/>
  1004. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1005. <LinearLayout
  1006.     xmlns:android="http://schemas.android.com/apk/res/android"
  1007.     xmlns:tools="http://schemas.android.com/tools"
  1008.     android:layout_width="match_parent"
  1009.     android:layout_height="match_parent"
  1010.     tools:context=".MainActivity"
  1011.     android:orientation="vertical"
  1012.     android:gravity="center"
  1013.     android:background="#FFFFFF"
  1014.     android:id="@+id/parent">
  1015.     <TextView
  1016.         android:layout_width="wrap_content"
  1017.         android:layout_height="wrap_content"
  1018.         android:text="Hello World"
  1019.         android:textSize="60sp"
  1020.         android:textColor="#669933"/>
  1021. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  1022. <LinearLayout
  1023.     xmlns:android="http://schemas.android.com/apk/res/android"
  1024.     xmlns:tools="http://schemas.android.com/tools"
  1025.     android:layout_width="match_parent"
  1026.     android:layout_height="match_parent"
  1027.     tools:context=".MainActivity"
  1028.     android:orientation="vertical"
  1029.     android:gravity="center"
  1030.     android:background="#FFFFFF"
  1031.     android:id="@+id/parent">
  1032.     <TextView
  1033.         android:layout_width="wrap_content"
  1034.         android:layout_height="wrap_content"
  1035.         android:text="Hello World"
  1036.         android:textSize="60sp"
  1037.         android:textColor="#669933"/>
  1038. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  1039. <LinearLayout
  1040.     xmlns:android="http://schemas.android.com/apk/res/android"
  1041.     xmlns:tools="http://schemas.android.com/tools"
  1042.     android:layout_width="match_parent"
  1043.     android:layout_height="match_parent"
  1044.     tools:context=".MainActivity"
  1045.     android:orientation="vertical"
  1046.     android:gravity="center"
  1047.     android:background="#FFFFFF"
  1048.     android:id="@+id/parent">
  1049.     <TextView
  1050.         android:layout_width="wrap_content"
  1051.         android:layout_height="wrap_content"
  1052.         android:text="Hello World"
  1053.         android:textSize="60sp"
  1054.         android:textColor="#669933"/>
  1055. </LinearLayout>public void stopRenderer() {<?xml version="1.0" encoding="utf-8"?>
  1056. <LinearLayout
  1057.     xmlns:android="http://schemas.android.com/apk/res/android"
  1058.     xmlns:tools="http://schemas.android.com/tools"
  1059.     android:layout_width="match_parent"
  1060.     android:layout_height="match_parent"
  1061.     tools:context=".MainActivity"
  1062.     android:orientation="vertical"
  1063.     android:gravity="center"
  1064.     android:background="#FFFFFF"
  1065.     android:id="@+id/parent">
  1066.     <TextView
  1067.         android:layout_width="wrap_content"
  1068.         android:layout_height="wrap_content"
  1069.         android:text="Hello World"
  1070.         android:textSize="60sp"
  1071.         android:textColor="#669933"/>
  1072. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1073. <LinearLayout
  1074.     xmlns:android="http://schemas.android.com/apk/res/android"
  1075.     xmlns:tools="http://schemas.android.com/tools"
  1076.     android:layout_width="match_parent"
  1077.     android:layout_height="match_parent"
  1078.     tools:context=".MainActivity"
  1079.     android:orientation="vertical"
  1080.     android:gravity="center"
  1081.     android:background="#FFFFFF"
  1082.     android:id="@+id/parent">
  1083.     <TextView
  1084.         android:layout_width="wrap_content"
  1085.         android:layout_height="wrap_content"
  1086.         android:text="Hello World"
  1087.         android:textSize="60sp"
  1088.         android:textColor="#669933"/>
  1089. </LinearLayout>mChoreographer.removeFrameCallback(mFrameCallback);<?xml version="1.0" encoding="utf-8"?>
  1090. <LinearLayout
  1091.     xmlns:android="http://schemas.android.com/apk/res/android"
  1092.     xmlns:tools="http://schemas.android.com/tools"
  1093.     android:layout_width="match_parent"
  1094.     android:layout_height="match_parent"
  1095.     tools:context=".MainActivity"
  1096.     android:orientation="vertical"
  1097.     android:gravity="center"
  1098.     android:background="#FFFFFF"
  1099.     android:id="@+id/parent">
  1100.     <TextView
  1101.         android:layout_width="wrap_content"
  1102.         android:layout_height="wrap_content"
  1103.         android:text="Hello World"
  1104.         android:textSize="60sp"
  1105.         android:textColor="#669933"/>
  1106. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  1107. <LinearLayout
  1108.     xmlns:android="http://schemas.android.com/apk/res/android"
  1109.     xmlns:tools="http://schemas.android.com/tools"
  1110.     android:layout_width="match_parent"
  1111.     android:layout_height="match_parent"
  1112.     tools:context=".MainActivity"
  1113.     android:orientation="vertical"
  1114.     android:gravity="center"
  1115.     android:background="#FFFFFF"
  1116.     android:id="@+id/parent">
  1117.     <TextView
  1118.         android:layout_width="wrap_content"
  1119.         android:layout_height="wrap_content"
  1120.         android:text="Hello World"
  1121.         android:textSize="60sp"
  1122.         android:textColor="#669933"/>
  1123. </LinearLayout>public void stopRenderer(long delay) {<?xml version="1.0" encoding="utf-8"?>
  1124. <LinearLayout
  1125.     xmlns:android="http://schemas.android.com/apk/res/android"
  1126.     xmlns:tools="http://schemas.android.com/tools"
  1127.     android:layout_width="match_parent"
  1128.     android:layout_height="match_parent"
  1129.     tools:context=".MainActivity"
  1130.     android:orientation="vertical"
  1131.     android:gravity="center"
  1132.     android:background="#FFFFFF"
  1133.     android:id="@+id/parent">
  1134.     <TextView
  1135.         android:layout_width="wrap_content"
  1136.         android:layout_height="wrap_content"
  1137.         android:text="Hello World"
  1138.         android:textSize="60sp"
  1139.         android:textColor="#669933"/>
  1140. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1141. <LinearLayout
  1142.     xmlns:android="http://schemas.android.com/apk/res/android"
  1143.     xmlns:tools="http://schemas.android.com/tools"
  1144.     android:layout_width="match_parent"
  1145.     android:layout_height="match_parent"
  1146.     tools:context=".MainActivity"
  1147.     android:orientation="vertical"
  1148.     android:gravity="center"
  1149.     android:background="#FFFFFF"
  1150.     android:id="@+id/parent">
  1151.     <TextView
  1152.         android:layout_width="wrap_content"
  1153.         android:layout_height="wrap_content"
  1154.         android:text="Hello World"
  1155.         android:textSize="60sp"
  1156.         android:textColor="#669933"/>
  1157. </LinearLayout>mHandler.removeCallbacksAndMessages(null);<?xml version="1.0" encoding="utf-8"?>
  1158. <LinearLayout
  1159.     xmlns:android="http://schemas.android.com/apk/res/android"
  1160.     xmlns:tools="http://schemas.android.com/tools"
  1161.     android:layout_width="match_parent"
  1162.     android:layout_height="match_parent"
  1163.     tools:context=".MainActivity"
  1164.     android:orientation="vertical"
  1165.     android:gravity="center"
  1166.     android:background="#FFFFFF"
  1167.     android:id="@+id/parent">
  1168.     <TextView
  1169.         android:layout_width="wrap_content"
  1170.         android:layout_height="wrap_content"
  1171.         android:text="Hello World"
  1172.         android:textSize="60sp"
  1173.         android:textColor="#669933"/>
  1174. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1175. <LinearLayout
  1176.     xmlns:android="http://schemas.android.com/apk/res/android"
  1177.     xmlns:tools="http://schemas.android.com/tools"
  1178.     android:layout_width="match_parent"
  1179.     android:layout_height="match_parent"
  1180.     tools:context=".MainActivity"
  1181.     android:orientation="vertical"
  1182.     android:gravity="center"
  1183.     android:background="#FFFFFF"
  1184.     android:id="@+id/parent">
  1185.     <TextView
  1186.         android:layout_width="wrap_content"
  1187.         android:layout_height="wrap_content"
  1188.         android:text="Hello World"
  1189.         android:textSize="60sp"
  1190.         android:textColor="#669933"/>
  1191. </LinearLayout>mHandler.postDelayed(() -> {<?xml version="1.0" encoding="utf-8"?>
  1192. <LinearLayout
  1193.     xmlns:android="http://schemas.android.com/apk/res/android"
  1194.     xmlns:tools="http://schemas.android.com/tools"
  1195.     android:layout_width="match_parent"
  1196.     android:layout_height="match_parent"
  1197.     tools:context=".MainActivity"
  1198.     android:orientation="vertical"
  1199.     android:gravity="center"
  1200.     android:background="#FFFFFF"
  1201.     android:id="@+id/parent">
  1202.     <TextView
  1203.         android:layout_width="wrap_content"
  1204.         android:layout_height="wrap_content"
  1205.         android:text="Hello World"
  1206.         android:textSize="60sp"
  1207.         android:textColor="#669933"/>
  1208. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1209. <LinearLayout
  1210.     xmlns:android="http://schemas.android.com/apk/res/android"
  1211.     xmlns:tools="http://schemas.android.com/tools"
  1212.     android:layout_width="match_parent"
  1213.     android:layout_height="match_parent"
  1214.     tools:context=".MainActivity"
  1215.     android:orientation="vertical"
  1216.     android:gravity="center"
  1217.     android:background="#FFFFFF"
  1218.     android:id="@+id/parent">
  1219.     <TextView
  1220.         android:layout_width="wrap_content"
  1221.         android:layout_height="wrap_content"
  1222.         android:text="Hello World"
  1223.         android:textSize="60sp"
  1224.         android:textColor="#669933"/>
  1225. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1226. <LinearLayout
  1227.     xmlns:android="http://schemas.android.com/apk/res/android"
  1228.     xmlns:tools="http://schemas.android.com/tools"
  1229.     android:layout_width="match_parent"
  1230.     android:layout_height="match_parent"
  1231.     tools:context=".MainActivity"
  1232.     android:orientation="vertical"
  1233.     android:gravity="center"
  1234.     android:background="#FFFFFF"
  1235.     android:id="@+id/parent">
  1236.     <TextView
  1237.         android:layout_width="wrap_content"
  1238.         android:layout_height="wrap_content"
  1239.         android:text="Hello World"
  1240.         android:textSize="60sp"
  1241.         android:textColor="#669933"/>
  1242. </LinearLayout>mChoreographer.removeFrameCallback(mFrameCallback);<?xml version="1.0" encoding="utf-8"?>
  1243. <LinearLayout
  1244.     xmlns:android="http://schemas.android.com/apk/res/android"
  1245.     xmlns:tools="http://schemas.android.com/tools"
  1246.     android:layout_width="match_parent"
  1247.     android:layout_height="match_parent"
  1248.     tools:context=".MainActivity"
  1249.     android:orientation="vertical"
  1250.     android:gravity="center"
  1251.     android:background="#FFFFFF"
  1252.     android:id="@+id/parent">
  1253.     <TextView
  1254.         android:layout_width="wrap_content"
  1255.         android:layout_height="wrap_content"
  1256.         android:text="Hello World"
  1257.         android:textSize="60sp"
  1258.         android:textColor="#669933"/>
  1259. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1260. <LinearLayout
  1261.     xmlns:android="http://schemas.android.com/apk/res/android"
  1262.     xmlns:tools="http://schemas.android.com/tools"
  1263.     android:layout_width="match_parent"
  1264.     android:layout_height="match_parent"
  1265.     tools:context=".MainActivity"
  1266.     android:orientation="vertical"
  1267.     android:gravity="center"
  1268.     android:background="#FFFFFF"
  1269.     android:id="@+id/parent">
  1270.     <TextView
  1271.         android:layout_width="wrap_content"
  1272.         android:layout_height="wrap_content"
  1273.         android:text="Hello World"
  1274.         android:textSize="60sp"
  1275.         android:textColor="#669933"/>
  1276. </LinearLayout>}, delay);<?xml version="1.0" encoding="utf-8"?>
  1277. <LinearLayout
  1278.     xmlns:android="http://schemas.android.com/apk/res/android"
  1279.     xmlns:tools="http://schemas.android.com/tools"
  1280.     android:layout_width="match_parent"
  1281.     android:layout_height="match_parent"
  1282.     tools:context=".MainActivity"
  1283.     android:orientation="vertical"
  1284.     android:gravity="center"
  1285.     android:background="#FFFFFF"
  1286.     android:id="@+id/parent">
  1287.     <TextView
  1288.         android:layout_width="wrap_content"
  1289.         android:layout_height="wrap_content"
  1290.         android:text="Hello World"
  1291.         android:textSize="60sp"
  1292.         android:textColor="#669933"/>
  1293. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  1294. <LinearLayout
  1295.     xmlns:android="http://schemas.android.com/apk/res/android"
  1296.     xmlns:tools="http://schemas.android.com/tools"
  1297.     android:layout_width="match_parent"
  1298.     android:layout_height="match_parent"
  1299.     tools:context=".MainActivity"
  1300.     android:orientation="vertical"
  1301.     android:gravity="center"
  1302.     android:background="#FFFFFF"
  1303.     android:id="@+id/parent">
  1304.     <TextView
  1305.         android:layout_width="wrap_content"
  1306.         android:layout_height="wrap_content"
  1307.         android:text="Hello World"
  1308.         android:textSize="60sp"
  1309.         android:textColor="#669933"/>
  1310. </LinearLayout>@Override<?xml version="1.0" encoding="utf-8"?>
  1311. <LinearLayout
  1312.     xmlns:android="http://schemas.android.com/apk/res/android"
  1313.     xmlns:tools="http://schemas.android.com/tools"
  1314.     android:layout_width="match_parent"
  1315.     android:layout_height="match_parent"
  1316.     tools:context=".MainActivity"
  1317.     android:orientation="vertical"
  1318.     android:gravity="center"
  1319.     android:background="#FFFFFF"
  1320.     android:id="@+id/parent">
  1321.     <TextView
  1322.         android:layout_width="wrap_content"
  1323.         android:layout_height="wrap_content"
  1324.         android:text="Hello World"
  1325.         android:textSize="60sp"
  1326.         android:textColor="#669933"/>
  1327. </LinearLayout>public void onSizeChanged(int w, int h, int oldw, int oldh) {<?xml version="1.0" encoding="utf-8"?>
  1328. <LinearLayout
  1329.     xmlns:android="http://schemas.android.com/apk/res/android"
  1330.     xmlns:tools="http://schemas.android.com/tools"
  1331.     android:layout_width="match_parent"
  1332.     android:layout_height="match_parent"
  1333.     tools:context=".MainActivity"
  1334.     android:orientation="vertical"
  1335.     android:gravity="center"
  1336.     android:background="#FFFFFF"
  1337.     android:id="@+id/parent">
  1338.     <TextView
  1339.         android:layout_width="wrap_content"
  1340.         android:layout_height="wrap_content"
  1341.         android:text="Hello World"
  1342.         android:textSize="60sp"
  1343.         android:textColor="#669933"/>
  1344. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1345. <LinearLayout
  1346.     xmlns:android="http://schemas.android.com/apk/res/android"
  1347.     xmlns:tools="http://schemas.android.com/tools"
  1348.     android:layout_width="match_parent"
  1349.     android:layout_height="match_parent"
  1350.     tools:context=".MainActivity"
  1351.     android:orientation="vertical"
  1352.     android:gravity="center"
  1353.     android:background="#FFFFFF"
  1354.     android:id="@+id/parent">
  1355.     <TextView
  1356.         android:layout_width="wrap_content"
  1357.         android:layout_height="wrap_content"
  1358.         android:text="Hello World"
  1359.         android:textSize="60sp"
  1360.         android:textColor="#669933"/>
  1361. </LinearLayout>super.onSizeChanged(w, h, oldw, oldh);<?xml version="1.0" encoding="utf-8"?>
  1362. <LinearLayout
  1363.     xmlns:android="http://schemas.android.com/apk/res/android"
  1364.     xmlns:tools="http://schemas.android.com/tools"
  1365.     android:layout_width="match_parent"
  1366.     android:layout_height="match_parent"
  1367.     tools:context=".MainActivity"
  1368.     android:orientation="vertical"
  1369.     android:gravity="center"
  1370.     android:background="#FFFFFF"
  1371.     android:id="@+id/parent">
  1372.     <TextView
  1373.         android:layout_width="wrap_content"
  1374.         android:layout_height="wrap_content"
  1375.         android:text="Hello World"
  1376.         android:textSize="60sp"
  1377.         android:textColor="#669933"/>
  1378. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1379. <LinearLayout
  1380.     xmlns:android="http://schemas.android.com/apk/res/android"
  1381.     xmlns:tools="http://schemas.android.com/tools"
  1382.     android:layout_width="match_parent"
  1383.     android:layout_height="match_parent"
  1384.     tools:context=".MainActivity"
  1385.     android:orientation="vertical"
  1386.     android:gravity="center"
  1387.     android:background="#FFFFFF"
  1388.     android:id="@+id/parent">
  1389.     <TextView
  1390.         android:layout_width="wrap_content"
  1391.         android:layout_height="wrap_content"
  1392.         android:text="Hello World"
  1393.         android:textSize="60sp"
  1394.         android:textColor="#669933"/>
  1395. </LinearLayout>mResolution = new float[] { w, h };<?xml version="1.0" encoding="utf-8"?>
  1396. <LinearLayout
  1397.     xmlns:android="http://schemas.android.com/apk/res/android"
  1398.     xmlns:tools="http://schemas.android.com/tools"
  1399.     android:layout_width="match_parent"
  1400.     android:layout_height="match_parent"
  1401.     tools:context=".MainActivity"
  1402.     android:orientation="vertical"
  1403.     android:gravity="center"
  1404.     android:background="#FFFFFF"
  1405.     android:id="@+id/parent">
  1406.     <TextView
  1407.         android:layout_width="wrap_content"
  1408.         android:layout_height="wrap_content"
  1409.         android:text="Hello World"
  1410.         android:textSize="60sp"
  1411.         android:textColor="#669933"/>
  1412. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1413. <LinearLayout
  1414.     xmlns:android="http://schemas.android.com/apk/res/android"
  1415.     xmlns:tools="http://schemas.android.com/tools"
  1416.     android:layout_width="match_parent"
  1417.     android:layout_height="match_parent"
  1418.     tools:context=".MainActivity"
  1419.     android:orientation="vertical"
  1420.     android:gravity="center"
  1421.     android:background="#FFFFFF"
  1422.     android:id="@+id/parent">
  1423.     <TextView
  1424.         android:layout_width="wrap_content"
  1425.         android:layout_height="wrap_content"
  1426.         android:text="Hello World"
  1427.         android:textSize="60sp"
  1428.         android:textColor="#669933"/>
  1429. </LinearLayout>mRenderer.onSurfaceChanged(w, h);<?xml version="1.0" encoding="utf-8"?>
  1430. <LinearLayout
  1431.     xmlns:android="http://schemas.android.com/apk/res/android"
  1432.     xmlns:tools="http://schemas.android.com/tools"
  1433.     android:layout_width="match_parent"
  1434.     android:layout_height="match_parent"
  1435.     tools:context=".MainActivity"
  1436.     android:orientation="vertical"
  1437.     android:gravity="center"
  1438.     android:background="#FFFFFF"
  1439.     android:id="@+id/parent">
  1440.     <TextView
  1441.         android:layout_width="wrap_content"
  1442.         android:layout_height="wrap_content"
  1443.         android:text="Hello World"
  1444.         android:textSize="60sp"
  1445.         android:textColor="#669933"/>
  1446. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  1447. <LinearLayout
  1448.     xmlns:android="http://schemas.android.com/apk/res/android"
  1449.     xmlns:tools="http://schemas.android.com/tools"
  1450.     android:layout_width="match_parent"
  1451.     android:layout_height="match_parent"
  1452.     tools:context=".MainActivity"
  1453.     android:orientation="vertical"
  1454.     android:gravity="center"
  1455.     android:background="#FFFFFF"
  1456.     android:id="@+id/parent">
  1457.     <TextView
  1458.         android:layout_width="wrap_content"
  1459.         android:layout_height="wrap_content"
  1460.         android:text="Hello World"
  1461.         android:textSize="60sp"
  1462.         android:textColor="#669933"/>
  1463. </LinearLayout>@Override<?xml version="1.0" encoding="utf-8"?>
  1464. <LinearLayout
  1465.     xmlns:android="http://schemas.android.com/apk/res/android"
  1466.     xmlns:tools="http://schemas.android.com/tools"
  1467.     android:layout_width="match_parent"
  1468.     android:layout_height="match_parent"
  1469.     tools:context=".MainActivity"
  1470.     android:orientation="vertical"
  1471.     android:gravity="center"
  1472.     android:background="#FFFFFF"
  1473.     android:id="@+id/parent">
  1474.     <TextView
  1475.         android:layout_width="wrap_content"
  1476.         android:layout_height="wrap_content"
  1477.         android:text="Hello World"
  1478.         android:textSize="60sp"
  1479.         android:textColor="#669933"/>
  1480. </LinearLayout>public void onDraw(Canvas canvas) {<?xml version="1.0" encoding="utf-8"?>
  1481. <LinearLayout
  1482.     xmlns:android="http://schemas.android.com/apk/res/android"
  1483.     xmlns:tools="http://schemas.android.com/tools"
  1484.     android:layout_width="match_parent"
  1485.     android:layout_height="match_parent"
  1486.     tools:context=".MainActivity"
  1487.     android:orientation="vertical"
  1488.     android:gravity="center"
  1489.     android:background="#FFFFFF"
  1490.     android:id="@+id/parent">
  1491.     <TextView
  1492.         android:layout_width="wrap_content"
  1493.         android:layout_height="wrap_content"
  1494.         android:text="Hello World"
  1495.         android:textSize="60sp"
  1496.         android:textColor="#669933"/>
  1497. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1498. <LinearLayout
  1499.     xmlns:android="http://schemas.android.com/apk/res/android"
  1500.     xmlns:tools="http://schemas.android.com/tools"
  1501.     android:layout_width="match_parent"
  1502.     android:layout_height="match_parent"
  1503.     tools:context=".MainActivity"
  1504.     android:orientation="vertical"
  1505.     android:gravity="center"
  1506.     android:background="#FFFFFF"
  1507.     android:id="@+id/parent">
  1508.     <TextView
  1509.         android:layout_width="wrap_content"
  1510.         android:layout_height="wrap_content"
  1511.         android:text="Hello World"
  1512.         android:textSize="60sp"
  1513.         android:textColor="#669933"/>
  1514. </LinearLayout>super.onDraw(canvas);<?xml version="1.0" encoding="utf-8"?>
  1515. <LinearLayout
  1516.     xmlns:android="http://schemas.android.com/apk/res/android"
  1517.     xmlns:tools="http://schemas.android.com/tools"
  1518.     android:layout_width="match_parent"
  1519.     android:layout_height="match_parent"
  1520.     tools:context=".MainActivity"
  1521.     android:orientation="vertical"
  1522.     android:gravity="center"
  1523.     android:background="#FFFFFF"
  1524.     android:id="@+id/parent">
  1525.     <TextView
  1526.         android:layout_width="wrap_content"
  1527.         android:layout_height="wrap_content"
  1528.         android:text="Hello World"
  1529.         android:textSize="60sp"
  1530.         android:textColor="#669933"/>
  1531. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1532. <LinearLayout
  1533.     xmlns:android="http://schemas.android.com/apk/res/android"
  1534.     xmlns:tools="http://schemas.android.com/tools"
  1535.     android:layout_width="match_parent"
  1536.     android:layout_height="match_parent"
  1537.     tools:context=".MainActivity"
  1538.     android:orientation="vertical"
  1539.     android:gravity="center"
  1540.     android:background="#FFFFFF"
  1541.     android:id="@+id/parent">
  1542.     <TextView
  1543.         android:layout_width="wrap_content"
  1544.         android:layout_height="wrap_content"
  1545.         android:text="Hello World"
  1546.         android:textSize="60sp"
  1547.         android:textColor="#669933"/>
  1548. </LinearLayout>mRunTime = System.currentTimeMillis() - mStartTime;<?xml version="1.0" encoding="utf-8"?>
  1549. <LinearLayout
  1550.     xmlns:android="http://schemas.android.com/apk/res/android"
  1551.     xmlns:tools="http://schemas.android.com/tools"
  1552.     android:layout_width="match_parent"
  1553.     android:layout_height="match_parent"
  1554.     tools:context=".MainActivity"
  1555.     android:orientation="vertical"
  1556.     android:gravity="center"
  1557.     android:background="#FFFFFF"
  1558.     android:id="@+id/parent">
  1559.     <TextView
  1560.         android:layout_width="wrap_content"
  1561.         android:layout_height="wrap_content"
  1562.         android:text="Hello World"
  1563.         android:textSize="60sp"
  1564.         android:textColor="#669933"/>
  1565. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1566. <LinearLayout
  1567.     xmlns:android="http://schemas.android.com/apk/res/android"
  1568.     xmlns:tools="http://schemas.android.com/tools"
  1569.     android:layout_width="match_parent"
  1570.     android:layout_height="match_parent"
  1571.     tools:context=".MainActivity"
  1572.     android:orientation="vertical"
  1573.     android:gravity="center"
  1574.     android:background="#FFFFFF"
  1575.     android:id="@+id/parent">
  1576.     <TextView
  1577.         android:layout_width="wrap_content"
  1578.         android:layout_height="wrap_content"
  1579.         android:text="Hello World"
  1580.         android:textSize="60sp"
  1581.         android:textColor="#669933"/>
  1582. </LinearLayout>mRenderer.onDrawFrame(mRunTime);<?xml version="1.0" encoding="utf-8"?>
  1583. <LinearLayout
  1584.     xmlns:android="http://schemas.android.com/apk/res/android"
  1585.     xmlns:tools="http://schemas.android.com/tools"
  1586.     android:layout_width="match_parent"
  1587.     android:layout_height="match_parent"
  1588.     tools:context=".MainActivity"
  1589.     android:orientation="vertical"
  1590.     android:gravity="center"
  1591.     android:background="#FFFFFF"
  1592.     android:id="@+id/parent">
  1593.     <TextView
  1594.         android:layout_width="wrap_content"
  1595.         android:layout_height="wrap_content"
  1596.         android:text="Hello World"
  1597.         android:textSize="60sp"
  1598.         android:textColor="#669933"/>
  1599. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1600. <LinearLayout
  1601.     xmlns:android="http://schemas.android.com/apk/res/android"
  1602.     xmlns:tools="http://schemas.android.com/tools"
  1603.     android:layout_width="match_parent"
  1604.     android:layout_height="match_parent"
  1605.     tools:context=".MainActivity"
  1606.     android:orientation="vertical"
  1607.     android:gravity="center"
  1608.     android:background="#FFFFFF"
  1609.     android:id="@+id/parent">
  1610.     <TextView
  1611.         android:layout_width="wrap_content"
  1612.         android:layout_height="wrap_content"
  1613.         android:text="Hello World"
  1614.         android:textSize="60sp"
  1615.         android:textColor="#669933"/>
  1616. </LinearLayout>canvas.drawRect(0f, 0f, mResolution[0], mResolution[1], mPaint);<?xml version="1.0" encoding="utf-8"?>
  1617. <LinearLayout
  1618.     xmlns:android="http://schemas.android.com/apk/res/android"
  1619.     xmlns:tools="http://schemas.android.com/tools"
  1620.     android:layout_width="match_parent"
  1621.     android:layout_height="match_parent"
  1622.     tools:context=".MainActivity"
  1623.     android:orientation="vertical"
  1624.     android:gravity="center"
  1625.     android:background="#FFFFFF"
  1626.     android:id="@+id/parent">
  1627.     <TextView
  1628.         android:layout_width="wrap_content"
  1629.         android:layout_height="wrap_content"
  1630.         android:text="Hello World"
  1631.         android:textSize="60sp"
  1632.         android:textColor="#669933"/>
  1633. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  1634. <LinearLayout
  1635.     xmlns:android="http://schemas.android.com/apk/res/android"
  1636.     xmlns:tools="http://schemas.android.com/tools"
  1637.     android:layout_width="match_parent"
  1638.     android:layout_height="match_parent"
  1639.     tools:context=".MainActivity"
  1640.     android:orientation="vertical"
  1641.     android:gravity="center"
  1642.     android:background="#FFFFFF"
  1643.     android:id="@+id/parent">
  1644.     <TextView
  1645.         android:layout_width="wrap_content"
  1646.         android:layout_height="wrap_content"
  1647.         android:text="Hello World"
  1648.         android:textSize="60sp"
  1649.         android:textColor="#669933"/>
  1650. </LinearLayout>private Choreographer.FrameCallback mFrameCallback = new Choreographer.FrameCallback() {<?xml version="1.0" encoding="utf-8"?>
  1651. <LinearLayout
  1652.     xmlns:android="http://schemas.android.com/apk/res/android"
  1653.     xmlns:tools="http://schemas.android.com/tools"
  1654.     android:layout_width="match_parent"
  1655.     android:layout_height="match_parent"
  1656.     tools:context=".MainActivity"
  1657.     android:orientation="vertical"
  1658.     android:gravity="center"
  1659.     android:background="#FFFFFF"
  1660.     android:id="@+id/parent">
  1661.     <TextView
  1662.         android:layout_width="wrap_content"
  1663.         android:layout_height="wrap_content"
  1664.         android:text="Hello World"
  1665.         android:textSize="60sp"
  1666.         android:textColor="#669933"/>
  1667. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1668. <LinearLayout
  1669.     xmlns:android="http://schemas.android.com/apk/res/android"
  1670.     xmlns:tools="http://schemas.android.com/tools"
  1671.     android:layout_width="match_parent"
  1672.     android:layout_height="match_parent"
  1673.     tools:context=".MainActivity"
  1674.     android:orientation="vertical"
  1675.     android:gravity="center"
  1676.     android:background="#FFFFFF"
  1677.     android:id="@+id/parent">
  1678.     <TextView
  1679.         android:layout_width="wrap_content"
  1680.         android:layout_height="wrap_content"
  1681.         android:text="Hello World"
  1682.         android:textSize="60sp"
  1683.         android:textColor="#669933"/>
  1684. </LinearLayout>@Override<?xml version="1.0" encoding="utf-8"?>
  1685. <LinearLayout
  1686.     xmlns:android="http://schemas.android.com/apk/res/android"
  1687.     xmlns:tools="http://schemas.android.com/tools"
  1688.     android:layout_width="match_parent"
  1689.     android:layout_height="match_parent"
  1690.     tools:context=".MainActivity"
  1691.     android:orientation="vertical"
  1692.     android:gravity="center"
  1693.     android:background="#FFFFFF"
  1694.     android:id="@+id/parent">
  1695.     <TextView
  1696.         android:layout_width="wrap_content"
  1697.         android:layout_height="wrap_content"
  1698.         android:text="Hello World"
  1699.         android:textSize="60sp"
  1700.         android:textColor="#669933"/>
  1701. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1702. <LinearLayout
  1703.     xmlns:android="http://schemas.android.com/apk/res/android"
  1704.     xmlns:tools="http://schemas.android.com/tools"
  1705.     android:layout_width="match_parent"
  1706.     android:layout_height="match_parent"
  1707.     tools:context=".MainActivity"
  1708.     android:orientation="vertical"
  1709.     android:gravity="center"
  1710.     android:background="#FFFFFF"
  1711.     android:id="@+id/parent">
  1712.     <TextView
  1713.         android:layout_width="wrap_content"
  1714.         android:layout_height="wrap_content"
  1715.         android:text="Hello World"
  1716.         android:textSize="60sp"
  1717.         android:textColor="#669933"/>
  1718. </LinearLayout>public void doFrame(long frameTimeNanos) {<?xml version="1.0" encoding="utf-8"?>
  1719. <LinearLayout
  1720.     xmlns:android="http://schemas.android.com/apk/res/android"
  1721.     xmlns:tools="http://schemas.android.com/tools"
  1722.     android:layout_width="match_parent"
  1723.     android:layout_height="match_parent"
  1724.     tools:context=".MainActivity"
  1725.     android:orientation="vertical"
  1726.     android:gravity="center"
  1727.     android:background="#FFFFFF"
  1728.     android:id="@+id/parent">
  1729.     <TextView
  1730.         android:layout_width="wrap_content"
  1731.         android:layout_height="wrap_content"
  1732.         android:text="Hello World"
  1733.         android:textSize="60sp"
  1734.         android:textColor="#669933"/>
  1735. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1736. <LinearLayout
  1737.     xmlns:android="http://schemas.android.com/apk/res/android"
  1738.     xmlns:tools="http://schemas.android.com/tools"
  1739.     android:layout_width="match_parent"
  1740.     android:layout_height="match_parent"
  1741.     tools:context=".MainActivity"
  1742.     android:orientation="vertical"
  1743.     android:gravity="center"
  1744.     android:background="#FFFFFF"
  1745.     android:id="@+id/parent">
  1746.     <TextView
  1747.         android:layout_width="wrap_content"
  1748.         android:layout_height="wrap_content"
  1749.         android:text="Hello World"
  1750.         android:textSize="60sp"
  1751.         android:textColor="#669933"/>
  1752. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1753. <LinearLayout
  1754.     xmlns:android="http://schemas.android.com/apk/res/android"
  1755.     xmlns:tools="http://schemas.android.com/tools"
  1756.     android:layout_width="match_parent"
  1757.     android:layout_height="match_parent"
  1758.     tools:context=".MainActivity"
  1759.     android:orientation="vertical"
  1760.     android:gravity="center"
  1761.     android:background="#FFFFFF"
  1762.     android:id="@+id/parent">
  1763.     <TextView
  1764.         android:layout_width="wrap_content"
  1765.         android:layout_height="wrap_content"
  1766.         android:text="Hello World"
  1767.         android:textSize="60sp"
  1768.         android:textColor="#669933"/>
  1769. </LinearLayout>mChoreographer.postFrameCallback(this);<?xml version="1.0" encoding="utf-8"?>
  1770. <LinearLayout
  1771.     xmlns:android="http://schemas.android.com/apk/res/android"
  1772.     xmlns:tools="http://schemas.android.com/tools"
  1773.     android:layout_width="match_parent"
  1774.     android:layout_height="match_parent"
  1775.     tools:context=".MainActivity"
  1776.     android:orientation="vertical"
  1777.     android:gravity="center"
  1778.     android:background="#FFFFFF"
  1779.     android:id="@+id/parent">
  1780.     <TextView
  1781.         android:layout_width="wrap_content"
  1782.         android:layout_height="wrap_content"
  1783.         android:text="Hello World"
  1784.         android:textSize="60sp"
  1785.         android:textColor="#669933"/>
  1786. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1787. <LinearLayout
  1788.     xmlns:android="http://schemas.android.com/apk/res/android"
  1789.     xmlns:tools="http://schemas.android.com/tools"
  1790.     android:layout_width="match_parent"
  1791.     android:layout_height="match_parent"
  1792.     tools:context=".MainActivity"
  1793.     android:orientation="vertical"
  1794.     android:gravity="center"
  1795.     android:background="#FFFFFF"
  1796.     android:id="@+id/parent">
  1797.     <TextView
  1798.         android:layout_width="wrap_content"
  1799.         android:layout_height="wrap_content"
  1800.         android:text="Hello World"
  1801.         android:textSize="60sp"
  1802.         android:textColor="#669933"/>
  1803. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1804. <LinearLayout
  1805.     xmlns:android="http://schemas.android.com/apk/res/android"
  1806.     xmlns:tools="http://schemas.android.com/tools"
  1807.     android:layout_width="match_parent"
  1808.     android:layout_height="match_parent"
  1809.     tools:context=".MainActivity"
  1810.     android:orientation="vertical"
  1811.     android:gravity="center"
  1812.     android:background="#FFFFFF"
  1813.     android:id="@+id/parent">
  1814.     <TextView
  1815.         android:layout_width="wrap_content"
  1816.         android:layout_height="wrap_content"
  1817.         android:text="Hello World"
  1818.         android:textSize="60sp"
  1819.         android:textColor="#669933"/>
  1820. </LinearLayout>ShaderView.this.invalidate();<?xml version="1.0" encoding="utf-8"?>
  1821. <LinearLayout
  1822.     xmlns:android="http://schemas.android.com/apk/res/android"
  1823.     xmlns:tools="http://schemas.android.com/tools"
  1824.     android:layout_width="match_parent"
  1825.     android:layout_height="match_parent"
  1826.     tools:context=".MainActivity"
  1827.     android:orientation="vertical"
  1828.     android:gravity="center"
  1829.     android:background="#FFFFFF"
  1830.     android:id="@+id/parent">
  1831.     <TextView
  1832.         android:layout_width="wrap_content"
  1833.         android:layout_height="wrap_content"
  1834.         android:text="Hello World"
  1835.         android:textSize="60sp"
  1836.         android:textColor="#669933"/>
  1837. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1838. <LinearLayout
  1839.     xmlns:android="http://schemas.android.com/apk/res/android"
  1840.     xmlns:tools="http://schemas.android.com/tools"
  1841.     android:layout_width="match_parent"
  1842.     android:layout_height="match_parent"
  1843.     tools:context=".MainActivity"
  1844.     android:orientation="vertical"
  1845.     android:gravity="center"
  1846.     android:background="#FFFFFF"
  1847.     android:id="@+id/parent">
  1848.     <TextView
  1849.         android:layout_width="wrap_content"
  1850.         android:layout_height="wrap_content"
  1851.         android:text="Hello World"
  1852.         android:textSize="60sp"
  1853.         android:textColor="#669933"/>
  1854. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  1855. <LinearLayout
  1856.     xmlns:android="http://schemas.android.com/apk/res/android"
  1857.     xmlns:tools="http://schemas.android.com/tools"
  1858.     android:layout_width="match_parent"
  1859.     android:layout_height="match_parent"
  1860.     tools:context=".MainActivity"
  1861.     android:orientation="vertical"
  1862.     android:gravity="center"
  1863.     android:background="#FFFFFF"
  1864.     android:id="@+id/parent">
  1865.     <TextView
  1866.         android:layout_width="wrap_content"
  1867.         android:layout_height="wrap_content"
  1868.         android:text="Hello World"
  1869.         android:textSize="60sp"
  1870.         android:textColor="#669933"/>
  1871. </LinearLayout>};<?xml version="1.0" encoding="utf-8"?>
  1872. <LinearLayout
  1873.     xmlns:android="http://schemas.android.com/apk/res/android"
  1874.     xmlns:tools="http://schemas.android.com/tools"
  1875.     android:layout_width="match_parent"
  1876.     android:layout_height="match_parent"
  1877.     tools:context=".MainActivity"
  1878.     android:orientation="vertical"
  1879.     android:gravity="center"
  1880.     android:background="#FFFFFF"
  1881.     android:id="@+id/parent">
  1882.     <TextView
  1883.         android:layout_width="wrap_content"
  1884.         android:layout_height="wrap_content"
  1885.         android:text="Hello World"
  1886.         android:textSize="60sp"
  1887.         android:textColor="#669933"/>
  1888. </LinearLayout>/**<?xml version="1.0" encoding="utf-8"?>
  1889. <LinearLayout
  1890.     xmlns:android="http://schemas.android.com/apk/res/android"
  1891.     xmlns:tools="http://schemas.android.com/tools"
  1892.     android:layout_width="match_parent"
  1893.     android:layout_height="match_parent"
  1894.     tools:context=".MainActivity"
  1895.     android:orientation="vertical"
  1896.     android:gravity="center"
  1897.     android:background="#FFFFFF"
  1898.     android:id="@+id/parent">
  1899.     <TextView
  1900.         android:layout_width="wrap_content"
  1901.         android:layout_height="wrap_content"
  1902.         android:text="Hello World"
  1903.         android:textSize="60sp"
  1904.         android:textColor="#669933"/>
  1905. </LinearLayout> * 渲染器接口, 类比GLSurfaceView.Renderer<?xml version="1.0" encoding="utf-8"?>
  1906. <LinearLayout
  1907.     xmlns:android="http://schemas.android.com/apk/res/android"
  1908.     xmlns:tools="http://schemas.android.com/tools"
  1909.     android:layout_width="match_parent"
  1910.     android:layout_height="match_parent"
  1911.     tools:context=".MainActivity"
  1912.     android:orientation="vertical"
  1913.     android:gravity="center"
  1914.     android:background="#FFFFFF"
  1915.     android:id="@+id/parent">
  1916.     <TextView
  1917.         android:layout_width="wrap_content"
  1918.         android:layout_height="wrap_content"
  1919.         android:text="Hello World"
  1920.         android:textSize="60sp"
  1921.         android:textColor="#669933"/>
  1922. </LinearLayout> * @author little fat sheep<?xml version="1.0" encoding="utf-8"?>
  1923. <LinearLayout
  1924.     xmlns:android="http://schemas.android.com/apk/res/android"
  1925.     xmlns:tools="http://schemas.android.com/tools"
  1926.     android:layout_width="match_parent"
  1927.     android:layout_height="match_parent"
  1928.     tools:context=".MainActivity"
  1929.     android:orientation="vertical"
  1930.     android:gravity="center"
  1931.     android:background="#FFFFFF"
  1932.     android:id="@+id/parent">
  1933.     <TextView
  1934.         android:layout_width="wrap_content"
  1935.         android:layout_height="wrap_content"
  1936.         android:text="Hello World"
  1937.         android:textSize="60sp"
  1938.         android:textColor="#669933"/>
  1939. </LinearLayout> */<?xml version="1.0" encoding="utf-8"?>
  1940. <LinearLayout
  1941.     xmlns:android="http://schemas.android.com/apk/res/android"
  1942.     xmlns:tools="http://schemas.android.com/tools"
  1943.     android:layout_width="match_parent"
  1944.     android:layout_height="match_parent"
  1945.     tools:context=".MainActivity"
  1946.     android:orientation="vertical"
  1947.     android:gravity="center"
  1948.     android:background="#FFFFFF"
  1949.     android:id="@+id/parent">
  1950.     <TextView
  1951.         android:layout_width="wrap_content"
  1952.         android:layout_height="wrap_content"
  1953.         android:text="Hello World"
  1954.         android:textSize="60sp"
  1955.         android:textColor="#669933"/>
  1956. </LinearLayout>public interface Renderer {<?xml version="1.0" encoding="utf-8"?>
  1957. <LinearLayout
  1958.     xmlns:android="http://schemas.android.com/apk/res/android"
  1959.     xmlns:tools="http://schemas.android.com/tools"
  1960.     android:layout_width="match_parent"
  1961.     android:layout_height="match_parent"
  1962.     tools:context=".MainActivity"
  1963.     android:orientation="vertical"
  1964.     android:gravity="center"
  1965.     android:background="#FFFFFF"
  1966.     android:id="@+id/parent">
  1967.     <TextView
  1968.         android:layout_width="wrap_content"
  1969.         android:layout_height="wrap_content"
  1970.         android:text="Hello World"
  1971.         android:textSize="60sp"
  1972.         android:textColor="#669933"/>
  1973. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  1974. <LinearLayout
  1975.     xmlns:android="http://schemas.android.com/apk/res/android"
  1976.     xmlns:tools="http://schemas.android.com/tools"
  1977.     android:layout_width="match_parent"
  1978.     android:layout_height="match_parent"
  1979.     tools:context=".MainActivity"
  1980.     android:orientation="vertical"
  1981.     android:gravity="center"
  1982.     android:background="#FFFFFF"
  1983.     android:id="@+id/parent">
  1984.     <TextView
  1985.         android:layout_width="wrap_content"
  1986.         android:layout_height="wrap_content"
  1987.         android:text="Hello World"
  1988.         android:textSize="60sp"
  1989.         android:textColor="#669933"/>
  1990. </LinearLayout>RuntimeShader onSurfaceCreated();<?xml version="1.0" encoding="utf-8"?>
  1991. <LinearLayout
  1992.     xmlns:android="http://schemas.android.com/apk/res/android"
  1993.     xmlns:tools="http://schemas.android.com/tools"
  1994.     android:layout_width="match_parent"
  1995.     android:layout_height="match_parent"
  1996.     tools:context=".MainActivity"
  1997.     android:orientation="vertical"
  1998.     android:gravity="center"
  1999.     android:background="#FFFFFF"
  2000.     android:id="@+id/parent">
  2001.     <TextView
  2002.         android:layout_width="wrap_content"
  2003.         android:layout_height="wrap_content"
  2004.         android:text="Hello World"
  2005.         android:textSize="60sp"
  2006.         android:textColor="#669933"/>
  2007. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  2008. <LinearLayout
  2009.     xmlns:android="http://schemas.android.com/apk/res/android"
  2010.     xmlns:tools="http://schemas.android.com/tools"
  2011.     android:layout_width="match_parent"
  2012.     android:layout_height="match_parent"
  2013.     tools:context=".MainActivity"
  2014.     android:orientation="vertical"
  2015.     android:gravity="center"
  2016.     android:background="#FFFFFF"
  2017.     android:id="@+id/parent">
  2018.     <TextView
  2019.         android:layout_width="wrap_content"
  2020.         android:layout_height="wrap_content"
  2021.         android:text="Hello World"
  2022.         android:textSize="60sp"
  2023.         android:textColor="#669933"/>
  2024. </LinearLayout>void onSurfaceChanged(int width, int height);<?xml version="1.0" encoding="utf-8"?>
  2025. <LinearLayout
  2026.     xmlns:android="http://schemas.android.com/apk/res/android"
  2027.     xmlns:tools="http://schemas.android.com/tools"
  2028.     android:layout_width="match_parent"
  2029.     android:layout_height="match_parent"
  2030.     tools:context=".MainActivity"
  2031.     android:orientation="vertical"
  2032.     android:gravity="center"
  2033.     android:background="#FFFFFF"
  2034.     android:id="@+id/parent">
  2035.     <TextView
  2036.         android:layout_width="wrap_content"
  2037.         android:layout_height="wrap_content"
  2038.         android:text="Hello World"
  2039.         android:textSize="60sp"
  2040.         android:textColor="#669933"/>
  2041. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  2042. <LinearLayout
  2043.     xmlns:android="http://schemas.android.com/apk/res/android"
  2044.     xmlns:tools="http://schemas.android.com/tools"
  2045.     android:layout_width="match_parent"
  2046.     android:layout_height="match_parent"
  2047.     tools:context=".MainActivity"
  2048.     android:orientation="vertical"
  2049.     android:gravity="center"
  2050.     android:background="#FFFFFF"
  2051.     android:id="@+id/parent">
  2052.     <TextView
  2053.         android:layout_width="wrap_content"
  2054.         android:layout_height="wrap_content"
  2055.         android:text="Hello World"
  2056.         android:textSize="60sp"
  2057.         android:textColor="#669933"/>
  2058. </LinearLayout>void onDrawFrame(long runTime);<?xml version="1.0" encoding="utf-8"?>
  2059. <LinearLayout
  2060.     xmlns:android="http://schemas.android.com/apk/res/android"
  2061.     xmlns:tools="http://schemas.android.com/tools"
  2062.     android:layout_width="match_parent"
  2063.     android:layout_height="match_parent"
  2064.     tools:context=".MainActivity"
  2065.     android:orientation="vertical"
  2066.     android:gravity="center"
  2067.     android:background="#FFFFFF"
  2068.     android:id="@+id/parent">
  2069.     <TextView
  2070.         android:layout_width="wrap_content"
  2071.         android:layout_height="wrap_content"
  2072.         android:text="Hello World"
  2073.         android:textSize="60sp"
  2074.         android:textColor="#669933"/>
  2075. </LinearLayout>}}
复制代码
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>BitmapTexture.java
  1. package com.zhyan8.shaderdemo.graphics;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapShader;import android.graphics.RuntimeShader;import android.graphics.Shader;import com.zhyan8.shaderdemo.utils.BitmapUtils;/** * Bitmap纹理 * @author little fat sheep */public class BitmapTexture {<?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:gravity="center"
  10.     android:background="#FFFFFF"
  11.     android:id="@+id/parent">
  12.     <TextView
  13.         android:layout_width="wrap_content"
  14.         android:layout_height="wrap_content"
  15.         android:text="Hello World"
  16.         android:textSize="60sp"
  17.         android:textColor="#669933"/>
  18. </LinearLayout>private BitmapShader mBitmapShader;<?xml version="1.0" encoding="utf-8"?>
  19. <LinearLayout
  20.     xmlns:android="http://schemas.android.com/apk/res/android"
  21.     xmlns:tools="http://schemas.android.com/tools"
  22.     android:layout_width="match_parent"
  23.     android:layout_height="match_parent"
  24.     tools:context=".MainActivity"
  25.     android:orientation="vertical"
  26.     android:gravity="center"
  27.     android:background="#FFFFFF"
  28.     android:id="@+id/parent">
  29.     <TextView
  30.         android:layout_width="wrap_content"
  31.         android:layout_height="wrap_content"
  32.         android:text="Hello World"
  33.         android:textSize="60sp"
  34.         android:textColor="#669933"/>
  35. </LinearLayout>private float[] mSize;<?xml version="1.0" encoding="utf-8"?>
  36. <LinearLayout
  37.     xmlns:android="http://schemas.android.com/apk/res/android"
  38.     xmlns:tools="http://schemas.android.com/tools"
  39.     android:layout_width="match_parent"
  40.     android:layout_height="match_parent"
  41.     tools:context=".MainActivity"
  42.     android:orientation="vertical"
  43.     android:gravity="center"
  44.     android:background="#FFFFFF"
  45.     android:id="@+id/parent">
  46.     <TextView
  47.         android:layout_width="wrap_content"
  48.         android:layout_height="wrap_content"
  49.         android:text="Hello World"
  50.         android:textSize="60sp"
  51.         android:textColor="#669933"/>
  52. </LinearLayout>private BitmapTexture(BitmapShader bitmapShader, float[] size) {<?xml version="1.0" encoding="utf-8"?>
  53. <LinearLayout
  54.     xmlns:android="http://schemas.android.com/apk/res/android"
  55.     xmlns:tools="http://schemas.android.com/tools"
  56.     android:layout_width="match_parent"
  57.     android:layout_height="match_parent"
  58.     tools:context=".MainActivity"
  59.     android:orientation="vertical"
  60.     android:gravity="center"
  61.     android:background="#FFFFFF"
  62.     android:id="@+id/parent">
  63.     <TextView
  64.         android:layout_width="wrap_content"
  65.         android:layout_height="wrap_content"
  66.         android:text="Hello World"
  67.         android:textSize="60sp"
  68.         android:textColor="#669933"/>
  69. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  70. <LinearLayout
  71.     xmlns:android="http://schemas.android.com/apk/res/android"
  72.     xmlns:tools="http://schemas.android.com/tools"
  73.     android:layout_width="match_parent"
  74.     android:layout_height="match_parent"
  75.     tools:context=".MainActivity"
  76.     android:orientation="vertical"
  77.     android:gravity="center"
  78.     android:background="#FFFFFF"
  79.     android:id="@+id/parent">
  80.     <TextView
  81.         android:layout_width="wrap_content"
  82.         android:layout_height="wrap_content"
  83.         android:text="Hello World"
  84.         android:textSize="60sp"
  85.         android:textColor="#669933"/>
  86. </LinearLayout>this.mBitmapShader = bitmapShader;<?xml version="1.0" encoding="utf-8"?>
  87. <LinearLayout
  88.     xmlns:android="http://schemas.android.com/apk/res/android"
  89.     xmlns:tools="http://schemas.android.com/tools"
  90.     android:layout_width="match_parent"
  91.     android:layout_height="match_parent"
  92.     tools:context=".MainActivity"
  93.     android:orientation="vertical"
  94.     android:gravity="center"
  95.     android:background="#FFFFFF"
  96.     android:id="@+id/parent">
  97.     <TextView
  98.         android:layout_width="wrap_content"
  99.         android:layout_height="wrap_content"
  100.         android:text="Hello World"
  101.         android:textSize="60sp"
  102.         android:textColor="#669933"/>
  103. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  104. <LinearLayout
  105.     xmlns:android="http://schemas.android.com/apk/res/android"
  106.     xmlns:tools="http://schemas.android.com/tools"
  107.     android:layout_width="match_parent"
  108.     android:layout_height="match_parent"
  109.     tools:context=".MainActivity"
  110.     android:orientation="vertical"
  111.     android:gravity="center"
  112.     android:background="#FFFFFF"
  113.     android:id="@+id/parent">
  114.     <TextView
  115.         android:layout_width="wrap_content"
  116.         android:layout_height="wrap_content"
  117.         android:text="Hello World"
  118.         android:textSize="60sp"
  119.         android:textColor="#669933"/>
  120. </LinearLayout>this.mSize = size;<?xml version="1.0" encoding="utf-8"?>
  121. <LinearLayout
  122.     xmlns:android="http://schemas.android.com/apk/res/android"
  123.     xmlns:tools="http://schemas.android.com/tools"
  124.     android:layout_width="match_parent"
  125.     android:layout_height="match_parent"
  126.     tools:context=".MainActivity"
  127.     android:orientation="vertical"
  128.     android:gravity="center"
  129.     android:background="#FFFFFF"
  130.     android:id="@+id/parent">
  131.     <TextView
  132.         android:layout_width="wrap_content"
  133.         android:layout_height="wrap_content"
  134.         android:text="Hello World"
  135.         android:textSize="60sp"
  136.         android:textColor="#669933"/>
  137. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  138. <LinearLayout
  139.     xmlns:android="http://schemas.android.com/apk/res/android"
  140.     xmlns:tools="http://schemas.android.com/tools"
  141.     android:layout_width="match_parent"
  142.     android:layout_height="match_parent"
  143.     tools:context=".MainActivity"
  144.     android:orientation="vertical"
  145.     android:gravity="center"
  146.     android:background="#FFFFFF"
  147.     android:id="@+id/parent">
  148.     <TextView
  149.         android:layout_width="wrap_content"
  150.         android:layout_height="wrap_content"
  151.         android:text="Hello World"
  152.         android:textSize="60sp"
  153.         android:textColor="#669933"/>
  154. </LinearLayout>public static BitmapTexture create(Context context, String assetPath) {<?xml version="1.0" encoding="utf-8"?>
  155. <LinearLayout
  156.     xmlns:android="http://schemas.android.com/apk/res/android"
  157.     xmlns:tools="http://schemas.android.com/tools"
  158.     android:layout_width="match_parent"
  159.     android:layout_height="match_parent"
  160.     tools:context=".MainActivity"
  161.     android:orientation="vertical"
  162.     android:gravity="center"
  163.     android:background="#FFFFFF"
  164.     android:id="@+id/parent">
  165.     <TextView
  166.         android:layout_width="wrap_content"
  167.         android:layout_height="wrap_content"
  168.         android:text="Hello World"
  169.         android:textSize="60sp"
  170.         android:textColor="#669933"/>
  171. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  172. <LinearLayout
  173.     xmlns:android="http://schemas.android.com/apk/res/android"
  174.     xmlns:tools="http://schemas.android.com/tools"
  175.     android:layout_width="match_parent"
  176.     android:layout_height="match_parent"
  177.     tools:context=".MainActivity"
  178.     android:orientation="vertical"
  179.     android:gravity="center"
  180.     android:background="#FFFFFF"
  181.     android:id="@+id/parent">
  182.     <TextView
  183.         android:layout_width="wrap_content"
  184.         android:layout_height="wrap_content"
  185.         android:text="Hello World"
  186.         android:textSize="60sp"
  187.         android:textColor="#669933"/>
  188. </LinearLayout>Bitmap bitmap = BitmapUtils.loadBitmapFromAsset(context, assetPath);<?xml version="1.0" encoding="utf-8"?>
  189. <LinearLayout
  190.     xmlns:android="http://schemas.android.com/apk/res/android"
  191.     xmlns:tools="http://schemas.android.com/tools"
  192.     android:layout_width="match_parent"
  193.     android:layout_height="match_parent"
  194.     tools:context=".MainActivity"
  195.     android:orientation="vertical"
  196.     android:gravity="center"
  197.     android:background="#FFFFFF"
  198.     android:id="@+id/parent">
  199.     <TextView
  200.         android:layout_width="wrap_content"
  201.         android:layout_height="wrap_content"
  202.         android:text="Hello World"
  203.         android:textSize="60sp"
  204.         android:textColor="#669933"/>
  205. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  206. <LinearLayout
  207.     xmlns:android="http://schemas.android.com/apk/res/android"
  208.     xmlns:tools="http://schemas.android.com/tools"
  209.     android:layout_width="match_parent"
  210.     android:layout_height="match_parent"
  211.     tools:context=".MainActivity"
  212.     android:orientation="vertical"
  213.     android:gravity="center"
  214.     android:background="#FFFFFF"
  215.     android:id="@+id/parent">
  216.     <TextView
  217.         android:layout_width="wrap_content"
  218.         android:layout_height="wrap_content"
  219.         android:text="Hello World"
  220.         android:textSize="60sp"
  221.         android:textColor="#669933"/>
  222. </LinearLayout>return create(bitmap);<?xml version="1.0" encoding="utf-8"?>
  223. <LinearLayout
  224.     xmlns:android="http://schemas.android.com/apk/res/android"
  225.     xmlns:tools="http://schemas.android.com/tools"
  226.     android:layout_width="match_parent"
  227.     android:layout_height="match_parent"
  228.     tools:context=".MainActivity"
  229.     android:orientation="vertical"
  230.     android:gravity="center"
  231.     android:background="#FFFFFF"
  232.     android:id="@+id/parent">
  233.     <TextView
  234.         android:layout_width="wrap_content"
  235.         android:layout_height="wrap_content"
  236.         android:text="Hello World"
  237.         android:textSize="60sp"
  238.         android:textColor="#669933"/>
  239. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  240. <LinearLayout
  241.     xmlns:android="http://schemas.android.com/apk/res/android"
  242.     xmlns:tools="http://schemas.android.com/tools"
  243.     android:layout_width="match_parent"
  244.     android:layout_height="match_parent"
  245.     tools:context=".MainActivity"
  246.     android:orientation="vertical"
  247.     android:gravity="center"
  248.     android:background="#FFFFFF"
  249.     android:id="@+id/parent">
  250.     <TextView
  251.         android:layout_width="wrap_content"
  252.         android:layout_height="wrap_content"
  253.         android:text="Hello World"
  254.         android:textSize="60sp"
  255.         android:textColor="#669933"/>
  256. </LinearLayout>public static BitmapTexture create(Context context, int rawId) {<?xml version="1.0" encoding="utf-8"?>
  257. <LinearLayout
  258.     xmlns:android="http://schemas.android.com/apk/res/android"
  259.     xmlns:tools="http://schemas.android.com/tools"
  260.     android:layout_width="match_parent"
  261.     android:layout_height="match_parent"
  262.     tools:context=".MainActivity"
  263.     android:orientation="vertical"
  264.     android:gravity="center"
  265.     android:background="#FFFFFF"
  266.     android:id="@+id/parent">
  267.     <TextView
  268.         android:layout_width="wrap_content"
  269.         android:layout_height="wrap_content"
  270.         android:text="Hello World"
  271.         android:textSize="60sp"
  272.         android:textColor="#669933"/>
  273. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  274. <LinearLayout
  275.     xmlns:android="http://schemas.android.com/apk/res/android"
  276.     xmlns:tools="http://schemas.android.com/tools"
  277.     android:layout_width="match_parent"
  278.     android:layout_height="match_parent"
  279.     tools:context=".MainActivity"
  280.     android:orientation="vertical"
  281.     android:gravity="center"
  282.     android:background="#FFFFFF"
  283.     android:id="@+id/parent">
  284.     <TextView
  285.         android:layout_width="wrap_content"
  286.         android:layout_height="wrap_content"
  287.         android:text="Hello World"
  288.         android:textSize="60sp"
  289.         android:textColor="#669933"/>
  290. </LinearLayout>Bitmap bitmap = BitmapUtils.loadBitmapFromRaw(context, rawId);<?xml version="1.0" encoding="utf-8"?>
  291. <LinearLayout
  292.     xmlns:android="http://schemas.android.com/apk/res/android"
  293.     xmlns:tools="http://schemas.android.com/tools"
  294.     android:layout_width="match_parent"
  295.     android:layout_height="match_parent"
  296.     tools:context=".MainActivity"
  297.     android:orientation="vertical"
  298.     android:gravity="center"
  299.     android:background="#FFFFFF"
  300.     android:id="@+id/parent">
  301.     <TextView
  302.         android:layout_width="wrap_content"
  303.         android:layout_height="wrap_content"
  304.         android:text="Hello World"
  305.         android:textSize="60sp"
  306.         android:textColor="#669933"/>
  307. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  308. <LinearLayout
  309.     xmlns:android="http://schemas.android.com/apk/res/android"
  310.     xmlns:tools="http://schemas.android.com/tools"
  311.     android:layout_width="match_parent"
  312.     android:layout_height="match_parent"
  313.     tools:context=".MainActivity"
  314.     android:orientation="vertical"
  315.     android:gravity="center"
  316.     android:background="#FFFFFF"
  317.     android:id="@+id/parent">
  318.     <TextView
  319.         android:layout_width="wrap_content"
  320.         android:layout_height="wrap_content"
  321.         android:text="Hello World"
  322.         android:textSize="60sp"
  323.         android:textColor="#669933"/>
  324. </LinearLayout>return create(bitmap);<?xml version="1.0" encoding="utf-8"?>
  325. <LinearLayout
  326.     xmlns:android="http://schemas.android.com/apk/res/android"
  327.     xmlns:tools="http://schemas.android.com/tools"
  328.     android:layout_width="match_parent"
  329.     android:layout_height="match_parent"
  330.     tools:context=".MainActivity"
  331.     android:orientation="vertical"
  332.     android:gravity="center"
  333.     android:background="#FFFFFF"
  334.     android:id="@+id/parent">
  335.     <TextView
  336.         android:layout_width="wrap_content"
  337.         android:layout_height="wrap_content"
  338.         android:text="Hello World"
  339.         android:textSize="60sp"
  340.         android:textColor="#669933"/>
  341. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  342. <LinearLayout
  343.     xmlns:android="http://schemas.android.com/apk/res/android"
  344.     xmlns:tools="http://schemas.android.com/tools"
  345.     android:layout_width="match_parent"
  346.     android:layout_height="match_parent"
  347.     tools:context=".MainActivity"
  348.     android:orientation="vertical"
  349.     android:gravity="center"
  350.     android:background="#FFFFFF"
  351.     android:id="@+id/parent">
  352.     <TextView
  353.         android:layout_width="wrap_content"
  354.         android:layout_height="wrap_content"
  355.         android:text="Hello World"
  356.         android:textSize="60sp"
  357.         android:textColor="#669933"/>
  358. </LinearLayout>public static BitmapTexture create(Bitmap bitmap) {<?xml version="1.0" encoding="utf-8"?>
  359. <LinearLayout
  360.     xmlns:android="http://schemas.android.com/apk/res/android"
  361.     xmlns:tools="http://schemas.android.com/tools"
  362.     android:layout_width="match_parent"
  363.     android:layout_height="match_parent"
  364.     tools:context=".MainActivity"
  365.     android:orientation="vertical"
  366.     android:gravity="center"
  367.     android:background="#FFFFFF"
  368.     android:id="@+id/parent">
  369.     <TextView
  370.         android:layout_width="wrap_content"
  371.         android:layout_height="wrap_content"
  372.         android:text="Hello World"
  373.         android:textSize="60sp"
  374.         android:textColor="#669933"/>
  375. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  376. <LinearLayout
  377.     xmlns:android="http://schemas.android.com/apk/res/android"
  378.     xmlns:tools="http://schemas.android.com/tools"
  379.     android:layout_width="match_parent"
  380.     android:layout_height="match_parent"
  381.     tools:context=".MainActivity"
  382.     android:orientation="vertical"
  383.     android:gravity="center"
  384.     android:background="#FFFFFF"
  385.     android:id="@+id/parent">
  386.     <TextView
  387.         android:layout_width="wrap_content"
  388.         android:layout_height="wrap_content"
  389.         android:text="Hello World"
  390.         android:textSize="60sp"
  391.         android:textColor="#669933"/>
  392. </LinearLayout>BitmapShader bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);<?xml version="1.0" encoding="utf-8"?>
  393. <LinearLayout
  394.     xmlns:android="http://schemas.android.com/apk/res/android"
  395.     xmlns:tools="http://schemas.android.com/tools"
  396.     android:layout_width="match_parent"
  397.     android:layout_height="match_parent"
  398.     tools:context=".MainActivity"
  399.     android:orientation="vertical"
  400.     android:gravity="center"
  401.     android:background="#FFFFFF"
  402.     android:id="@+id/parent">
  403.     <TextView
  404.         android:layout_width="wrap_content"
  405.         android:layout_height="wrap_content"
  406.         android:text="Hello World"
  407.         android:textSize="60sp"
  408.         android:textColor="#669933"/>
  409. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  410. <LinearLayout
  411.     xmlns:android="http://schemas.android.com/apk/res/android"
  412.     xmlns:tools="http://schemas.android.com/tools"
  413.     android:layout_width="match_parent"
  414.     android:layout_height="match_parent"
  415.     tools:context=".MainActivity"
  416.     android:orientation="vertical"
  417.     android:gravity="center"
  418.     android:background="#FFFFFF"
  419.     android:id="@+id/parent">
  420.     <TextView
  421.         android:layout_width="wrap_content"
  422.         android:layout_height="wrap_content"
  423.         android:text="Hello World"
  424.         android:textSize="60sp"
  425.         android:textColor="#669933"/>
  426. </LinearLayout>float[] size = new float[] { bitmap.getWidth(), bitmap.getHeight() };<?xml version="1.0" encoding="utf-8"?>
  427. <LinearLayout
  428.     xmlns:android="http://schemas.android.com/apk/res/android"
  429.     xmlns:tools="http://schemas.android.com/tools"
  430.     android:layout_width="match_parent"
  431.     android:layout_height="match_parent"
  432.     tools:context=".MainActivity"
  433.     android:orientation="vertical"
  434.     android:gravity="center"
  435.     android:background="#FFFFFF"
  436.     android:id="@+id/parent">
  437.     <TextView
  438.         android:layout_width="wrap_content"
  439.         android:layout_height="wrap_content"
  440.         android:text="Hello World"
  441.         android:textSize="60sp"
  442.         android:textColor="#669933"/>
  443. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  444. <LinearLayout
  445.     xmlns:android="http://schemas.android.com/apk/res/android"
  446.     xmlns:tools="http://schemas.android.com/tools"
  447.     android:layout_width="match_parent"
  448.     android:layout_height="match_parent"
  449.     tools:context=".MainActivity"
  450.     android:orientation="vertical"
  451.     android:gravity="center"
  452.     android:background="#FFFFFF"
  453.     android:id="@+id/parent">
  454.     <TextView
  455.         android:layout_width="wrap_content"
  456.         android:layout_height="wrap_content"
  457.         android:text="Hello World"
  458.         android:textSize="60sp"
  459.         android:textColor="#669933"/>
  460. </LinearLayout>return new BitmapTexture(bitmapShader, size);<?xml version="1.0" encoding="utf-8"?>
  461. <LinearLayout
  462.     xmlns:android="http://schemas.android.com/apk/res/android"
  463.     xmlns:tools="http://schemas.android.com/tools"
  464.     android:layout_width="match_parent"
  465.     android:layout_height="match_parent"
  466.     tools:context=".MainActivity"
  467.     android:orientation="vertical"
  468.     android:gravity="center"
  469.     android:background="#FFFFFF"
  470.     android:id="@+id/parent">
  471.     <TextView
  472.         android:layout_width="wrap_content"
  473.         android:layout_height="wrap_content"
  474.         android:text="Hello World"
  475.         android:textSize="60sp"
  476.         android:textColor="#669933"/>
  477. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  478. <LinearLayout
  479.     xmlns:android="http://schemas.android.com/apk/res/android"
  480.     xmlns:tools="http://schemas.android.com/tools"
  481.     android:layout_width="match_parent"
  482.     android:layout_height="match_parent"
  483.     tools:context=".MainActivity"
  484.     android:orientation="vertical"
  485.     android:gravity="center"
  486.     android:background="#FFFFFF"
  487.     android:id="@+id/parent">
  488.     <TextView
  489.         android:layout_width="wrap_content"
  490.         android:layout_height="wrap_content"
  491.         android:text="Hello World"
  492.         android:textSize="60sp"
  493.         android:textColor="#669933"/>
  494. </LinearLayout>public void bind(RuntimeShader shader, String textureName, String sizeName) {<?xml version="1.0" encoding="utf-8"?>
  495. <LinearLayout
  496.     xmlns:android="http://schemas.android.com/apk/res/android"
  497.     xmlns:tools="http://schemas.android.com/tools"
  498.     android:layout_width="match_parent"
  499.     android:layout_height="match_parent"
  500.     tools:context=".MainActivity"
  501.     android:orientation="vertical"
  502.     android:gravity="center"
  503.     android:background="#FFFFFF"
  504.     android:id="@+id/parent">
  505.     <TextView
  506.         android:layout_width="wrap_content"
  507.         android:layout_height="wrap_content"
  508.         android:text="Hello World"
  509.         android:textSize="60sp"
  510.         android:textColor="#669933"/>
  511. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  512. <LinearLayout
  513.     xmlns:android="http://schemas.android.com/apk/res/android"
  514.     xmlns:tools="http://schemas.android.com/tools"
  515.     android:layout_width="match_parent"
  516.     android:layout_height="match_parent"
  517.     tools:context=".MainActivity"
  518.     android:orientation="vertical"
  519.     android:gravity="center"
  520.     android:background="#FFFFFF"
  521.     android:id="@+id/parent">
  522.     <TextView
  523.         android:layout_width="wrap_content"
  524.         android:layout_height="wrap_content"
  525.         android:text="Hello World"
  526.         android:textSize="60sp"
  527.         android:textColor="#669933"/>
  528. </LinearLayout>shader.setInputShader(textureName, mBitmapShader);<?xml version="1.0" encoding="utf-8"?>
  529. <LinearLayout
  530.     xmlns:android="http://schemas.android.com/apk/res/android"
  531.     xmlns:tools="http://schemas.android.com/tools"
  532.     android:layout_width="match_parent"
  533.     android:layout_height="match_parent"
  534.     tools:context=".MainActivity"
  535.     android:orientation="vertical"
  536.     android:gravity="center"
  537.     android:background="#FFFFFF"
  538.     android:id="@+id/parent">
  539.     <TextView
  540.         android:layout_width="wrap_content"
  541.         android:layout_height="wrap_content"
  542.         android:text="Hello World"
  543.         android:textSize="60sp"
  544.         android:textColor="#669933"/>
  545. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  546. <LinearLayout
  547.     xmlns:android="http://schemas.android.com/apk/res/android"
  548.     xmlns:tools="http://schemas.android.com/tools"
  549.     android:layout_width="match_parent"
  550.     android:layout_height="match_parent"
  551.     tools:context=".MainActivity"
  552.     android:orientation="vertical"
  553.     android:gravity="center"
  554.     android:background="#FFFFFF"
  555.     android:id="@+id/parent">
  556.     <TextView
  557.         android:layout_width="wrap_content"
  558.         android:layout_height="wrap_content"
  559.         android:text="Hello World"
  560.         android:textSize="60sp"
  561.         android:textColor="#669933"/>
  562. </LinearLayout>shader.setFloatUniform(sizeName, mSize);<?xml version="1.0" encoding="utf-8"?>
  563. <LinearLayout
  564.     xmlns:android="http://schemas.android.com/apk/res/android"
  565.     xmlns:tools="http://schemas.android.com/tools"
  566.     android:layout_width="match_parent"
  567.     android:layout_height="match_parent"
  568.     tools:context=".MainActivity"
  569.     android:orientation="vertical"
  570.     android:gravity="center"
  571.     android:background="#FFFFFF"
  572.     android:id="@+id/parent">
  573.     <TextView
  574.         android:layout_width="wrap_content"
  575.         android:layout_height="wrap_content"
  576.         android:text="Hello World"
  577.         android:textSize="60sp"
  578.         android:textColor="#669933"/>
  579. </LinearLayout>}}
复制代码
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>MyRenderer.java
  1. package com.zhyan8.shaderdemo;import android.content.Context;import android.graphics.RuntimeShader;import com.zhyan8.shaderdemo.graphics.BitmapTexture;import com.zhyan8.shaderdemo.graphics.ShaderView;import com.zhyan8.shaderdemo.utils.StringUtils;public class MyRenderer implements ShaderView.Renderer {<?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:gravity="center"
  10.     android:background="#FFFFFF"
  11.     android:id="@+id/parent">
  12.     <TextView
  13.         android:layout_width="wrap_content"
  14.         android:layout_height="wrap_content"
  15.         android:text="Hello World"
  16.         android:textSize="60sp"
  17.         android:textColor="#669933"/>
  18. </LinearLayout>private Context mContext;<?xml version="1.0" encoding="utf-8"?>
  19. <LinearLayout
  20.     xmlns:android="http://schemas.android.com/apk/res/android"
  21.     xmlns:tools="http://schemas.android.com/tools"
  22.     android:layout_width="match_parent"
  23.     android:layout_height="match_parent"
  24.     tools:context=".MainActivity"
  25.     android:orientation="vertical"
  26.     android:gravity="center"
  27.     android:background="#FFFFFF"
  28.     android:id="@+id/parent">
  29.     <TextView
  30.         android:layout_width="wrap_content"
  31.         android:layout_height="wrap_content"
  32.         android:text="Hello World"
  33.         android:textSize="60sp"
  34.         android:textColor="#669933"/>
  35. </LinearLayout>private RuntimeShader mShader;<?xml version="1.0" encoding="utf-8"?>
  36. <LinearLayout
  37.     xmlns:android="http://schemas.android.com/apk/res/android"
  38.     xmlns:tools="http://schemas.android.com/tools"
  39.     android:layout_width="match_parent"
  40.     android:layout_height="match_parent"
  41.     tools:context=".MainActivity"
  42.     android:orientation="vertical"
  43.     android:gravity="center"
  44.     android:background="#FFFFFF"
  45.     android:id="@+id/parent">
  46.     <TextView
  47.         android:layout_width="wrap_content"
  48.         android:layout_height="wrap_content"
  49.         android:text="Hello World"
  50.         android:textSize="60sp"
  51.         android:textColor="#669933"/>
  52. </LinearLayout>private float[] mResolution;<?xml version="1.0" encoding="utf-8"?>
  53. <LinearLayout
  54.     xmlns:android="http://schemas.android.com/apk/res/android"
  55.     xmlns:tools="http://schemas.android.com/tools"
  56.     android:layout_width="match_parent"
  57.     android:layout_height="match_parent"
  58.     tools:context=".MainActivity"
  59.     android:orientation="vertical"
  60.     android:gravity="center"
  61.     android:background="#FFFFFF"
  62.     android:id="@+id/parent">
  63.     <TextView
  64.         android:layout_width="wrap_content"
  65.         android:layout_height="wrap_content"
  66.         android:text="Hello World"
  67.         android:textSize="60sp"
  68.         android:textColor="#669933"/>
  69. </LinearLayout>private BitmapTexture mBitmapTexture;<?xml version="1.0" encoding="utf-8"?>
  70. <LinearLayout
  71.     xmlns:android="http://schemas.android.com/apk/res/android"
  72.     xmlns:tools="http://schemas.android.com/tools"
  73.     android:layout_width="match_parent"
  74.     android:layout_height="match_parent"
  75.     tools:context=".MainActivity"
  76.     android:orientation="vertical"
  77.     android:gravity="center"
  78.     android:background="#FFFFFF"
  79.     android:id="@+id/parent">
  80.     <TextView
  81.         android:layout_width="wrap_content"
  82.         android:layout_height="wrap_content"
  83.         android:text="Hello World"
  84.         android:textSize="60sp"
  85.         android:textColor="#669933"/>
  86. </LinearLayout>public MyRenderer(Context context) {<?xml version="1.0" encoding="utf-8"?>
  87. <LinearLayout
  88.     xmlns:android="http://schemas.android.com/apk/res/android"
  89.     xmlns:tools="http://schemas.android.com/tools"
  90.     android:layout_width="match_parent"
  91.     android:layout_height="match_parent"
  92.     tools:context=".MainActivity"
  93.     android:orientation="vertical"
  94.     android:gravity="center"
  95.     android:background="#FFFFFF"
  96.     android:id="@+id/parent">
  97.     <TextView
  98.         android:layout_width="wrap_content"
  99.         android:layout_height="wrap_content"
  100.         android:text="Hello World"
  101.         android:textSize="60sp"
  102.         android:textColor="#669933"/>
  103. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  104. <LinearLayout
  105.     xmlns:android="http://schemas.android.com/apk/res/android"
  106.     xmlns:tools="http://schemas.android.com/tools"
  107.     android:layout_width="match_parent"
  108.     android:layout_height="match_parent"
  109.     tools:context=".MainActivity"
  110.     android:orientation="vertical"
  111.     android:gravity="center"
  112.     android:background="#FFFFFF"
  113.     android:id="@+id/parent">
  114.     <TextView
  115.         android:layout_width="wrap_content"
  116.         android:layout_height="wrap_content"
  117.         android:text="Hello World"
  118.         android:textSize="60sp"
  119.         android:textColor="#669933"/>
  120. </LinearLayout>this.mContext = context;<?xml version="1.0" encoding="utf-8"?>
  121. <LinearLayout
  122.     xmlns:android="http://schemas.android.com/apk/res/android"
  123.     xmlns:tools="http://schemas.android.com/tools"
  124.     android:layout_width="match_parent"
  125.     android:layout_height="match_parent"
  126.     tools:context=".MainActivity"
  127.     android:orientation="vertical"
  128.     android:gravity="center"
  129.     android:background="#FFFFFF"
  130.     android:id="@+id/parent">
  131.     <TextView
  132.         android:layout_width="wrap_content"
  133.         android:layout_height="wrap_content"
  134.         android:text="Hello World"
  135.         android:textSize="60sp"
  136.         android:textColor="#669933"/>
  137. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  138. <LinearLayout
  139.     xmlns:android="http://schemas.android.com/apk/res/android"
  140.     xmlns:tools="http://schemas.android.com/tools"
  141.     android:layout_width="match_parent"
  142.     android:layout_height="match_parent"
  143.     tools:context=".MainActivity"
  144.     android:orientation="vertical"
  145.     android:gravity="center"
  146.     android:background="#FFFFFF"
  147.     android:id="@+id/parent">
  148.     <TextView
  149.         android:layout_width="wrap_content"
  150.         android:layout_height="wrap_content"
  151.         android:text="Hello World"
  152.         android:textSize="60sp"
  153.         android:textColor="#669933"/>
  154. </LinearLayout>@Override<?xml version="1.0" encoding="utf-8"?>
  155. <LinearLayout
  156.     xmlns:android="http://schemas.android.com/apk/res/android"
  157.     xmlns:tools="http://schemas.android.com/tools"
  158.     android:layout_width="match_parent"
  159.     android:layout_height="match_parent"
  160.     tools:context=".MainActivity"
  161.     android:orientation="vertical"
  162.     android:gravity="center"
  163.     android:background="#FFFFFF"
  164.     android:id="@+id/parent">
  165.     <TextView
  166.         android:layout_width="wrap_content"
  167.         android:layout_height="wrap_content"
  168.         android:text="Hello World"
  169.         android:textSize="60sp"
  170.         android:textColor="#669933"/>
  171. </LinearLayout>public RuntimeShader onSurfaceCreated() {<?xml version="1.0" encoding="utf-8"?>
  172. <LinearLayout
  173.     xmlns:android="http://schemas.android.com/apk/res/android"
  174.     xmlns:tools="http://schemas.android.com/tools"
  175.     android:layout_width="match_parent"
  176.     android:layout_height="match_parent"
  177.     tools:context=".MainActivity"
  178.     android:orientation="vertical"
  179.     android:gravity="center"
  180.     android:background="#FFFFFF"
  181.     android:id="@+id/parent">
  182.     <TextView
  183.         android:layout_width="wrap_content"
  184.         android:layout_height="wrap_content"
  185.         android:text="Hello World"
  186.         android:textSize="60sp"
  187.         android:textColor="#669933"/>
  188. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  189. <LinearLayout
  190.     xmlns:android="http://schemas.android.com/apk/res/android"
  191.     xmlns:tools="http://schemas.android.com/tools"
  192.     android:layout_width="match_parent"
  193.     android:layout_height="match_parent"
  194.     tools:context=".MainActivity"
  195.     android:orientation="vertical"
  196.     android:gravity="center"
  197.     android:background="#FFFFFF"
  198.     android:id="@+id/parent">
  199.     <TextView
  200.         android:layout_width="wrap_content"
  201.         android:layout_height="wrap_content"
  202.         android:text="Hello World"
  203.         android:textSize="60sp"
  204.         android:textColor="#669933"/>
  205. </LinearLayout>String shaderCode = StringUtils.loadString(mContext, "shaders/jelly.agsl");<?xml version="1.0" encoding="utf-8"?>
  206. <LinearLayout
  207.     xmlns:android="http://schemas.android.com/apk/res/android"
  208.     xmlns:tools="http://schemas.android.com/tools"
  209.     android:layout_width="match_parent"
  210.     android:layout_height="match_parent"
  211.     tools:context=".MainActivity"
  212.     android:orientation="vertical"
  213.     android:gravity="center"
  214.     android:background="#FFFFFF"
  215.     android:id="@+id/parent">
  216.     <TextView
  217.         android:layout_width="wrap_content"
  218.         android:layout_height="wrap_content"
  219.         android:text="Hello World"
  220.         android:textSize="60sp"
  221.         android:textColor="#669933"/>
  222. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  223. <LinearLayout
  224.     xmlns:android="http://schemas.android.com/apk/res/android"
  225.     xmlns:tools="http://schemas.android.com/tools"
  226.     android:layout_width="match_parent"
  227.     android:layout_height="match_parent"
  228.     tools:context=".MainActivity"
  229.     android:orientation="vertical"
  230.     android:gravity="center"
  231.     android:background="#FFFFFF"
  232.     android:id="@+id/parent">
  233.     <TextView
  234.         android:layout_width="wrap_content"
  235.         android:layout_height="wrap_content"
  236.         android:text="Hello World"
  237.         android:textSize="60sp"
  238.         android:textColor="#669933"/>
  239. </LinearLayout>mShader = new RuntimeShader(shaderCode);<?xml version="1.0" encoding="utf-8"?>
  240. <LinearLayout
  241.     xmlns:android="http://schemas.android.com/apk/res/android"
  242.     xmlns:tools="http://schemas.android.com/tools"
  243.     android:layout_width="match_parent"
  244.     android:layout_height="match_parent"
  245.     tools:context=".MainActivity"
  246.     android:orientation="vertical"
  247.     android:gravity="center"
  248.     android:background="#FFFFFF"
  249.     android:id="@+id/parent">
  250.     <TextView
  251.         android:layout_width="wrap_content"
  252.         android:layout_height="wrap_content"
  253.         android:text="Hello World"
  254.         android:textSize="60sp"
  255.         android:textColor="#669933"/>
  256. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  257. <LinearLayout
  258.     xmlns:android="http://schemas.android.com/apk/res/android"
  259.     xmlns:tools="http://schemas.android.com/tools"
  260.     android:layout_width="match_parent"
  261.     android:layout_height="match_parent"
  262.     tools:context=".MainActivity"
  263.     android:orientation="vertical"
  264.     android:gravity="center"
  265.     android:background="#FFFFFF"
  266.     android:id="@+id/parent">
  267.     <TextView
  268.         android:layout_width="wrap_content"
  269.         android:layout_height="wrap_content"
  270.         android:text="Hello World"
  271.         android:textSize="60sp"
  272.         android:textColor="#669933"/>
  273. </LinearLayout>mBitmapTexture = BitmapTexture.create(mContext, "textures/photo.png");<?xml version="1.0" encoding="utf-8"?>
  274. <LinearLayout
  275.     xmlns:android="http://schemas.android.com/apk/res/android"
  276.     xmlns:tools="http://schemas.android.com/tools"
  277.     android:layout_width="match_parent"
  278.     android:layout_height="match_parent"
  279.     tools:context=".MainActivity"
  280.     android:orientation="vertical"
  281.     android:gravity="center"
  282.     android:background="#FFFFFF"
  283.     android:id="@+id/parent">
  284.     <TextView
  285.         android:layout_width="wrap_content"
  286.         android:layout_height="wrap_content"
  287.         android:text="Hello World"
  288.         android:textSize="60sp"
  289.         android:textColor="#669933"/>
  290. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  291. <LinearLayout
  292.     xmlns:android="http://schemas.android.com/apk/res/android"
  293.     xmlns:tools="http://schemas.android.com/tools"
  294.     android:layout_width="match_parent"
  295.     android:layout_height="match_parent"
  296.     tools:context=".MainActivity"
  297.     android:orientation="vertical"
  298.     android:gravity="center"
  299.     android:background="#FFFFFF"
  300.     android:id="@+id/parent">
  301.     <TextView
  302.         android:layout_width="wrap_content"
  303.         android:layout_height="wrap_content"
  304.         android:text="Hello World"
  305.         android:textSize="60sp"
  306.         android:textColor="#669933"/>
  307. </LinearLayout>return mShader;<?xml version="1.0" encoding="utf-8"?>
  308. <LinearLayout
  309.     xmlns:android="http://schemas.android.com/apk/res/android"
  310.     xmlns:tools="http://schemas.android.com/tools"
  311.     android:layout_width="match_parent"
  312.     android:layout_height="match_parent"
  313.     tools:context=".MainActivity"
  314.     android:orientation="vertical"
  315.     android:gravity="center"
  316.     android:background="#FFFFFF"
  317.     android:id="@+id/parent">
  318.     <TextView
  319.         android:layout_width="wrap_content"
  320.         android:layout_height="wrap_content"
  321.         android:text="Hello World"
  322.         android:textSize="60sp"
  323.         android:textColor="#669933"/>
  324. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  325. <LinearLayout
  326.     xmlns:android="http://schemas.android.com/apk/res/android"
  327.     xmlns:tools="http://schemas.android.com/tools"
  328.     android:layout_width="match_parent"
  329.     android:layout_height="match_parent"
  330.     tools:context=".MainActivity"
  331.     android:orientation="vertical"
  332.     android:gravity="center"
  333.     android:background="#FFFFFF"
  334.     android:id="@+id/parent">
  335.     <TextView
  336.         android:layout_width="wrap_content"
  337.         android:layout_height="wrap_content"
  338.         android:text="Hello World"
  339.         android:textSize="60sp"
  340.         android:textColor="#669933"/>
  341. </LinearLayout>@Override<?xml version="1.0" encoding="utf-8"?>
  342. <LinearLayout
  343.     xmlns:android="http://schemas.android.com/apk/res/android"
  344.     xmlns:tools="http://schemas.android.com/tools"
  345.     android:layout_width="match_parent"
  346.     android:layout_height="match_parent"
  347.     tools:context=".MainActivity"
  348.     android:orientation="vertical"
  349.     android:gravity="center"
  350.     android:background="#FFFFFF"
  351.     android:id="@+id/parent">
  352.     <TextView
  353.         android:layout_width="wrap_content"
  354.         android:layout_height="wrap_content"
  355.         android:text="Hello World"
  356.         android:textSize="60sp"
  357.         android:textColor="#669933"/>
  358. </LinearLayout>public void onSurfaceChanged(int width, int height) {<?xml version="1.0" encoding="utf-8"?>
  359. <LinearLayout
  360.     xmlns:android="http://schemas.android.com/apk/res/android"
  361.     xmlns:tools="http://schemas.android.com/tools"
  362.     android:layout_width="match_parent"
  363.     android:layout_height="match_parent"
  364.     tools:context=".MainActivity"
  365.     android:orientation="vertical"
  366.     android:gravity="center"
  367.     android:background="#FFFFFF"
  368.     android:id="@+id/parent">
  369.     <TextView
  370.         android:layout_width="wrap_content"
  371.         android:layout_height="wrap_content"
  372.         android:text="Hello World"
  373.         android:textSize="60sp"
  374.         android:textColor="#669933"/>
  375. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  376. <LinearLayout
  377.     xmlns:android="http://schemas.android.com/apk/res/android"
  378.     xmlns:tools="http://schemas.android.com/tools"
  379.     android:layout_width="match_parent"
  380.     android:layout_height="match_parent"
  381.     tools:context=".MainActivity"
  382.     android:orientation="vertical"
  383.     android:gravity="center"
  384.     android:background="#FFFFFF"
  385.     android:id="@+id/parent">
  386.     <TextView
  387.         android:layout_width="wrap_content"
  388.         android:layout_height="wrap_content"
  389.         android:text="Hello World"
  390.         android:textSize="60sp"
  391.         android:textColor="#669933"/>
  392. </LinearLayout>mResolution = new float[] { width, height };<?xml version="1.0" encoding="utf-8"?>
  393. <LinearLayout
  394.     xmlns:android="http://schemas.android.com/apk/res/android"
  395.     xmlns:tools="http://schemas.android.com/tools"
  396.     android:layout_width="match_parent"
  397.     android:layout_height="match_parent"
  398.     tools:context=".MainActivity"
  399.     android:orientation="vertical"
  400.     android:gravity="center"
  401.     android:background="#FFFFFF"
  402.     android:id="@+id/parent">
  403.     <TextView
  404.         android:layout_width="wrap_content"
  405.         android:layout_height="wrap_content"
  406.         android:text="Hello World"
  407.         android:textSize="60sp"
  408.         android:textColor="#669933"/>
  409. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  410. <LinearLayout
  411.     xmlns:android="http://schemas.android.com/apk/res/android"
  412.     xmlns:tools="http://schemas.android.com/tools"
  413.     android:layout_width="match_parent"
  414.     android:layout_height="match_parent"
  415.     tools:context=".MainActivity"
  416.     android:orientation="vertical"
  417.     android:gravity="center"
  418.     android:background="#FFFFFF"
  419.     android:id="@+id/parent">
  420.     <TextView
  421.         android:layout_width="wrap_content"
  422.         android:layout_height="wrap_content"
  423.         android:text="Hello World"
  424.         android:textSize="60sp"
  425.         android:textColor="#669933"/>
  426. </LinearLayout>@Override<?xml version="1.0" encoding="utf-8"?>
  427. <LinearLayout
  428.     xmlns:android="http://schemas.android.com/apk/res/android"
  429.     xmlns:tools="http://schemas.android.com/tools"
  430.     android:layout_width="match_parent"
  431.     android:layout_height="match_parent"
  432.     tools:context=".MainActivity"
  433.     android:orientation="vertical"
  434.     android:gravity="center"
  435.     android:background="#FFFFFF"
  436.     android:id="@+id/parent">
  437.     <TextView
  438.         android:layout_width="wrap_content"
  439.         android:layout_height="wrap_content"
  440.         android:text="Hello World"
  441.         android:textSize="60sp"
  442.         android:textColor="#669933"/>
  443. </LinearLayout>public void onDrawFrame(long runTime) {<?xml version="1.0" encoding="utf-8"?>
  444. <LinearLayout
  445.     xmlns:android="http://schemas.android.com/apk/res/android"
  446.     xmlns:tools="http://schemas.android.com/tools"
  447.     android:layout_width="match_parent"
  448.     android:layout_height="match_parent"
  449.     tools:context=".MainActivity"
  450.     android:orientation="vertical"
  451.     android:gravity="center"
  452.     android:background="#FFFFFF"
  453.     android:id="@+id/parent">
  454.     <TextView
  455.         android:layout_width="wrap_content"
  456.         android:layout_height="wrap_content"
  457.         android:text="Hello World"
  458.         android:textSize="60sp"
  459.         android:textColor="#669933"/>
  460. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  461. <LinearLayout
  462.     xmlns:android="http://schemas.android.com/apk/res/android"
  463.     xmlns:tools="http://schemas.android.com/tools"
  464.     android:layout_width="match_parent"
  465.     android:layout_height="match_parent"
  466.     tools:context=".MainActivity"
  467.     android:orientation="vertical"
  468.     android:gravity="center"
  469.     android:background="#FFFFFF"
  470.     android:id="@+id/parent">
  471.     <TextView
  472.         android:layout_width="wrap_content"
  473.         android:layout_height="wrap_content"
  474.         android:text="Hello World"
  475.         android:textSize="60sp"
  476.         android:textColor="#669933"/>
  477. </LinearLayout>mBitmapTexture.bind(mShader, "u_texture", "u_textureSize");<?xml version="1.0" encoding="utf-8"?>
  478. <LinearLayout
  479.     xmlns:android="http://schemas.android.com/apk/res/android"
  480.     xmlns:tools="http://schemas.android.com/tools"
  481.     android:layout_width="match_parent"
  482.     android:layout_height="match_parent"
  483.     tools:context=".MainActivity"
  484.     android:orientation="vertical"
  485.     android:gravity="center"
  486.     android:background="#FFFFFF"
  487.     android:id="@+id/parent">
  488.     <TextView
  489.         android:layout_width="wrap_content"
  490.         android:layout_height="wrap_content"
  491.         android:text="Hello World"
  492.         android:textSize="60sp"
  493.         android:textColor="#669933"/>
  494. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  495. <LinearLayout
  496.     xmlns:android="http://schemas.android.com/apk/res/android"
  497.     xmlns:tools="http://schemas.android.com/tools"
  498.     android:layout_width="match_parent"
  499.     android:layout_height="match_parent"
  500.     tools:context=".MainActivity"
  501.     android:orientation="vertical"
  502.     android:gravity="center"
  503.     android:background="#FFFFFF"
  504.     android:id="@+id/parent">
  505.     <TextView
  506.         android:layout_width="wrap_content"
  507.         android:layout_height="wrap_content"
  508.         android:text="Hello World"
  509.         android:textSize="60sp"
  510.         android:textColor="#669933"/>
  511. </LinearLayout>mShader.setFloatUniform("u_resolution", mResolution);<?xml version="1.0" encoding="utf-8"?>
  512. <LinearLayout
  513.     xmlns:android="http://schemas.android.com/apk/res/android"
  514.     xmlns:tools="http://schemas.android.com/tools"
  515.     android:layout_width="match_parent"
  516.     android:layout_height="match_parent"
  517.     tools:context=".MainActivity"
  518.     android:orientation="vertical"
  519.     android:gravity="center"
  520.     android:background="#FFFFFF"
  521.     android:id="@+id/parent">
  522.     <TextView
  523.         android:layout_width="wrap_content"
  524.         android:layout_height="wrap_content"
  525.         android:text="Hello World"
  526.         android:textSize="60sp"
  527.         android:textColor="#669933"/>
  528. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  529. <LinearLayout
  530.     xmlns:android="http://schemas.android.com/apk/res/android"
  531.     xmlns:tools="http://schemas.android.com/tools"
  532.     android:layout_width="match_parent"
  533.     android:layout_height="match_parent"
  534.     tools:context=".MainActivity"
  535.     android:orientation="vertical"
  536.     android:gravity="center"
  537.     android:background="#FFFFFF"
  538.     android:id="@+id/parent">
  539.     <TextView
  540.         android:layout_width="wrap_content"
  541.         android:layout_height="wrap_content"
  542.         android:text="Hello World"
  543.         android:textSize="60sp"
  544.         android:textColor="#669933"/>
  545. </LinearLayout>mShader.setFloatUniform("u_time", runTime / 1000f);<?xml version="1.0" encoding="utf-8"?>
  546. <LinearLayout
  547.     xmlns:android="http://schemas.android.com/apk/res/android"
  548.     xmlns:tools="http://schemas.android.com/tools"
  549.     android:layout_width="match_parent"
  550.     android:layout_height="match_parent"
  551.     tools:context=".MainActivity"
  552.     android:orientation="vertical"
  553.     android:gravity="center"
  554.     android:background="#FFFFFF"
  555.     android:id="@+id/parent">
  556.     <TextView
  557.         android:layout_width="wrap_content"
  558.         android:layout_height="wrap_content"
  559.         android:text="Hello World"
  560.         android:textSize="60sp"
  561.         android:textColor="#669933"/>
  562. </LinearLayout>}}
复制代码
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>jelly.agsl
  1. uniform shader u_texture;uniform vec2 u_textureSize;uniform vec2 u_resolution;uniform float u_time;vec4 texture(vec2 normUV) { // 纹理采样<?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:gravity="center"
  10.     android:background="#FFFFFF"
  11.     android:id="@+id/parent">
  12.     <TextView
  13.         android:layout_width="wrap_content"
  14.         android:layout_height="wrap_content"
  15.         android:text="Hello World"
  16.         android:textSize="60sp"
  17.         android:textColor="#669933"/>
  18. </LinearLayout>vec2 uv = normUV * u_textureSize;<?xml version="1.0" encoding="utf-8"?>
  19. <LinearLayout
  20.     xmlns:android="http://schemas.android.com/apk/res/android"
  21.     xmlns:tools="http://schemas.android.com/tools"
  22.     android:layout_width="match_parent"
  23.     android:layout_height="match_parent"
  24.     tools:context=".MainActivity"
  25.     android:orientation="vertical"
  26.     android:gravity="center"
  27.     android:background="#FFFFFF"
  28.     android:id="@+id/parent">
  29.     <TextView
  30.         android:layout_width="wrap_content"
  31.         android:layout_height="wrap_content"
  32.         android:text="Hello World"
  33.         android:textSize="60sp"
  34.         android:textColor="#669933"/>
  35. </LinearLayout>return u_texture.eval(uv);}vec2 fun(vec2 uv, float aspect) { // 畸变函数<?xml version="1.0" encoding="utf-8"?>
  36. <LinearLayout
  37.     xmlns:android="http://schemas.android.com/apk/res/android"
  38.     xmlns:tools="http://schemas.android.com/tools"
  39.     android:layout_width="match_parent"
  40.     android:layout_height="match_parent"
  41.     tools:context=".MainActivity"
  42.     android:orientation="vertical"
  43.     android:gravity="center"
  44.     android:background="#FFFFFF"
  45.     android:id="@+id/parent">
  46.     <TextView
  47.         android:layout_width="wrap_content"
  48.         android:layout_height="wrap_content"
  49.         android:text="Hello World"
  50.         android:textSize="60sp"
  51.         android:textColor="#669933"/>
  52. </LinearLayout>vec2 center = vec2(0.5, 0.5 / aspect);<?xml version="1.0" encoding="utf-8"?>
  53. <LinearLayout
  54.     xmlns:android="http://schemas.android.com/apk/res/android"
  55.     xmlns:tools="http://schemas.android.com/tools"
  56.     android:layout_width="match_parent"
  57.     android:layout_height="match_parent"
  58.     tools:context=".MainActivity"
  59.     android:orientation="vertical"
  60.     android:gravity="center"
  61.     android:background="#FFFFFF"
  62.     android:id="@+id/parent">
  63.     <TextView
  64.         android:layout_width="wrap_content"
  65.         android:layout_height="wrap_content"
  66.         android:text="Hello World"
  67.         android:textSize="60sp"
  68.         android:textColor="#669933"/>
  69. </LinearLayout>vec2 dire = normalize(uv - center);<?xml version="1.0" encoding="utf-8"?>
  70. <LinearLayout
  71.     xmlns:android="http://schemas.android.com/apk/res/android"
  72.     xmlns:tools="http://schemas.android.com/tools"
  73.     android:layout_width="match_parent"
  74.     android:layout_height="match_parent"
  75.     tools:context=".MainActivity"
  76.     android:orientation="vertical"
  77.     android:gravity="center"
  78.     android:background="#FFFFFF"
  79.     android:id="@+id/parent">
  80.     <TextView
  81.         android:layout_width="wrap_content"
  82.         android:layout_height="wrap_content"
  83.         android:text="Hello World"
  84.         android:textSize="60sp"
  85.         android:textColor="#669933"/>
  86. </LinearLayout>float dist = distance(uv, center);<?xml version="1.0" encoding="utf-8"?>
  87. <LinearLayout
  88.     xmlns:android="http://schemas.android.com/apk/res/android"
  89.     xmlns:tools="http://schemas.android.com/tools"
  90.     android:layout_width="match_parent"
  91.     android:layout_height="match_parent"
  92.     tools:context=".MainActivity"
  93.     android:orientation="vertical"
  94.     android:gravity="center"
  95.     android:background="#FFFFFF"
  96.     android:id="@+id/parent">
  97.     <TextView
  98.         android:layout_width="wrap_content"
  99.         android:layout_height="wrap_content"
  100.         android:text="Hello World"
  101.         android:textSize="60sp"
  102.         android:textColor="#669933"/>
  103. </LinearLayout>vec2 uv1 = uv + sin(dist * 2.2 + u_time * 3.5) * 0.025;<?xml version="1.0" encoding="utf-8"?>
  104. <LinearLayout
  105.     xmlns:android="http://schemas.android.com/apk/res/android"
  106.     xmlns:tools="http://schemas.android.com/tools"
  107.     android:layout_width="match_parent"
  108.     android:layout_height="match_parent"
  109.     tools:context=".MainActivity"
  110.     android:orientation="vertical"
  111.     android:gravity="center"
  112.     android:background="#FFFFFF"
  113.     android:id="@+id/parent">
  114.     <TextView
  115.         android:layout_width="wrap_content"
  116.         android:layout_height="wrap_content"
  117.         android:text="Hello World"
  118.         android:textSize="60sp"
  119.         android:textColor="#669933"/>
  120. </LinearLayout>return uv1;}vec4 main(vec2 coords) {<?xml version="1.0" encoding="utf-8"?>
  121. <LinearLayout
  122.     xmlns:android="http://schemas.android.com/apk/res/android"
  123.     xmlns:tools="http://schemas.android.com/tools"
  124.     android:layout_width="match_parent"
  125.     android:layout_height="match_parent"
  126.     tools:context=".MainActivity"
  127.     android:orientation="vertical"
  128.     android:gravity="center"
  129.     android:background="#FFFFFF"
  130.     android:id="@+id/parent">
  131.     <TextView
  132.         android:layout_width="wrap_content"
  133.         android:layout_height="wrap_content"
  134.         android:text="Hello World"
  135.         android:textSize="60sp"
  136.         android:textColor="#669933"/>
  137. </LinearLayout>vec2 normUV = coords / u_resolution;<?xml version="1.0" encoding="utf-8"?>
  138. <LinearLayout
  139.     xmlns:android="http://schemas.android.com/apk/res/android"
  140.     xmlns:tools="http://schemas.android.com/tools"
  141.     android:layout_width="match_parent"
  142.     android:layout_height="match_parent"
  143.     tools:context=".MainActivity"
  144.     android:orientation="vertical"
  145.     android:gravity="center"
  146.     android:background="#FFFFFF"
  147.     android:id="@+id/parent">
  148.     <TextView
  149.         android:layout_width="wrap_content"
  150.         android:layout_height="wrap_content"
  151.         android:text="Hello World"
  152.         android:textSize="60sp"
  153.         android:textColor="#669933"/>
  154. </LinearLayout>float aspect = u_resolution.x / u_resolution.y;<?xml version="1.0" encoding="utf-8"?>
  155. <LinearLayout
  156.     xmlns:android="http://schemas.android.com/apk/res/android"
  157.     xmlns:tools="http://schemas.android.com/tools"
  158.     android:layout_width="match_parent"
  159.     android:layout_height="match_parent"
  160.     tools:context=".MainActivity"
  161.     android:orientation="vertical"
  162.     android:gravity="center"
  163.     android:background="#FFFFFF"
  164.     android:id="@+id/parent">
  165.     <TextView
  166.         android:layout_width="wrap_content"
  167.         android:layout_height="wrap_content"
  168.         android:text="Hello World"
  169.         android:textSize="60sp"
  170.         android:textColor="#669933"/>
  171. </LinearLayout>normUV.y /= aspect;<?xml version="1.0" encoding="utf-8"?>
  172. <LinearLayout
  173.     xmlns:android="http://schemas.android.com/apk/res/android"
  174.     xmlns:tools="http://schemas.android.com/tools"
  175.     android:layout_width="match_parent"
  176.     android:layout_height="match_parent"
  177.     tools:context=".MainActivity"
  178.     android:orientation="vertical"
  179.     android:gravity="center"
  180.     android:background="#FFFFFF"
  181.     android:id="@+id/parent">
  182.     <TextView
  183.         android:layout_width="wrap_content"
  184.         android:layout_height="wrap_content"
  185.         android:text="Hello World"
  186.         android:textSize="60sp"
  187.         android:textColor="#669933"/>
  188. </LinearLayout>vec2 uv = fun(normUV, aspect);<?xml version="1.0" encoding="utf-8"?>
  189. <LinearLayout
  190.     xmlns:android="http://schemas.android.com/apk/res/android"
  191.     xmlns:tools="http://schemas.android.com/tools"
  192.     android:layout_width="match_parent"
  193.     android:layout_height="match_parent"
  194.     tools:context=".MainActivity"
  195.     android:orientation="vertical"
  196.     android:gravity="center"
  197.     android:background="#FFFFFF"
  198.     android:id="@+id/parent">
  199.     <TextView
  200.         android:layout_width="wrap_content"
  201.         android:layout_height="wrap_content"
  202.         android:text="Hello World"
  203.         android:textSize="60sp"
  204.         android:textColor="#669933"/>
  205. </LinearLayout>uv.y *= aspect;<?xml version="1.0" encoding="utf-8"?>
  206. <LinearLayout
  207.     xmlns:android="http://schemas.android.com/apk/res/android"
  208.     xmlns:tools="http://schemas.android.com/tools"
  209.     android:layout_width="match_parent"
  210.     android:layout_height="match_parent"
  211.     tools:context=".MainActivity"
  212.     android:orientation="vertical"
  213.     android:gravity="center"
  214.     android:background="#FFFFFF"
  215.     android:id="@+id/parent">
  216.     <TextView
  217.         android:layout_width="wrap_content"
  218.         android:layout_height="wrap_content"
  219.         android:text="Hello World"
  220.         android:textSize="60sp"
  221.         android:textColor="#669933"/>
  222. </LinearLayout>return texture(uv);}
复制代码
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>运行效果如下。
2.gif

3.2 二次渲染

​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>本节将对 3.1 节中 MyRenderer 进行修改,使用两个 RuntimeShader 实现二次渲染。
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>MyRenderer.java
  1. package com.zhyan8.shaderdemo;import android.content.Context;import android.graphics.RuntimeShader;import com.zhyan8.shaderdemo.graphics.BitmapTexture;import com.zhyan8.shaderdemo.graphics.ShaderView;import com.zhyan8.shaderdemo.utils.StringUtils;public class MyRenderer implements ShaderView.Renderer {<?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:gravity="center"
  10.     android:background="#FFFFFF"
  11.     android:id="@+id/parent">
  12.     <TextView
  13.         android:layout_width="wrap_content"
  14.         android:layout_height="wrap_content"
  15.         android:text="Hello World"
  16.         android:textSize="60sp"
  17.         android:textColor="#669933"/>
  18. </LinearLayout>private Context mContext;<?xml version="1.0" encoding="utf-8"?>
  19. <LinearLayout
  20.     xmlns:android="http://schemas.android.com/apk/res/android"
  21.     xmlns:tools="http://schemas.android.com/tools"
  22.     android:layout_width="match_parent"
  23.     android:layout_height="match_parent"
  24.     tools:context=".MainActivity"
  25.     android:orientation="vertical"
  26.     android:gravity="center"
  27.     android:background="#FFFFFF"
  28.     android:id="@+id/parent">
  29.     <TextView
  30.         android:layout_width="wrap_content"
  31.         android:layout_height="wrap_content"
  32.         android:text="Hello World"
  33.         android:textSize="60sp"
  34.         android:textColor="#669933"/>
  35. </LinearLayout>private RuntimeShader mShader1;<?xml version="1.0" encoding="utf-8"?>
  36. <LinearLayout
  37.     xmlns:android="http://schemas.android.com/apk/res/android"
  38.     xmlns:tools="http://schemas.android.com/tools"
  39.     android:layout_width="match_parent"
  40.     android:layout_height="match_parent"
  41.     tools:context=".MainActivity"
  42.     android:orientation="vertical"
  43.     android:gravity="center"
  44.     android:background="#FFFFFF"
  45.     android:id="@+id/parent">
  46.     <TextView
  47.         android:layout_width="wrap_content"
  48.         android:layout_height="wrap_content"
  49.         android:text="Hello World"
  50.         android:textSize="60sp"
  51.         android:textColor="#669933"/>
  52. </LinearLayout>private RuntimeShader mShader2;<?xml version="1.0" encoding="utf-8"?>
  53. <LinearLayout
  54.     xmlns:android="http://schemas.android.com/apk/res/android"
  55.     xmlns:tools="http://schemas.android.com/tools"
  56.     android:layout_width="match_parent"
  57.     android:layout_height="match_parent"
  58.     tools:context=".MainActivity"
  59.     android:orientation="vertical"
  60.     android:gravity="center"
  61.     android:background="#FFFFFF"
  62.     android:id="@+id/parent">
  63.     <TextView
  64.         android:layout_width="wrap_content"
  65.         android:layout_height="wrap_content"
  66.         android:text="Hello World"
  67.         android:textSize="60sp"
  68.         android:textColor="#669933"/>
  69. </LinearLayout>private float[] mResolution;<?xml version="1.0" encoding="utf-8"?>
  70. <LinearLayout
  71.     xmlns:android="http://schemas.android.com/apk/res/android"
  72.     xmlns:tools="http://schemas.android.com/tools"
  73.     android:layout_width="match_parent"
  74.     android:layout_height="match_parent"
  75.     tools:context=".MainActivity"
  76.     android:orientation="vertical"
  77.     android:gravity="center"
  78.     android:background="#FFFFFF"
  79.     android:id="@+id/parent">
  80.     <TextView
  81.         android:layout_width="wrap_content"
  82.         android:layout_height="wrap_content"
  83.         android:text="Hello World"
  84.         android:textSize="60sp"
  85.         android:textColor="#669933"/>
  86. </LinearLayout>private BitmapTexture mBitmapTexture;<?xml version="1.0" encoding="utf-8"?>
  87. <LinearLayout
  88.     xmlns:android="http://schemas.android.com/apk/res/android"
  89.     xmlns:tools="http://schemas.android.com/tools"
  90.     android:layout_width="match_parent"
  91.     android:layout_height="match_parent"
  92.     tools:context=".MainActivity"
  93.     android:orientation="vertical"
  94.     android:gravity="center"
  95.     android:background="#FFFFFF"
  96.     android:id="@+id/parent">
  97.     <TextView
  98.         android:layout_width="wrap_content"
  99.         android:layout_height="wrap_content"
  100.         android:text="Hello World"
  101.         android:textSize="60sp"
  102.         android:textColor="#669933"/>
  103. </LinearLayout>public MyRenderer(Context context) {<?xml version="1.0" encoding="utf-8"?>
  104. <LinearLayout
  105.     xmlns:android="http://schemas.android.com/apk/res/android"
  106.     xmlns:tools="http://schemas.android.com/tools"
  107.     android:layout_width="match_parent"
  108.     android:layout_height="match_parent"
  109.     tools:context=".MainActivity"
  110.     android:orientation="vertical"
  111.     android:gravity="center"
  112.     android:background="#FFFFFF"
  113.     android:id="@+id/parent">
  114.     <TextView
  115.         android:layout_width="wrap_content"
  116.         android:layout_height="wrap_content"
  117.         android:text="Hello World"
  118.         android:textSize="60sp"
  119.         android:textColor="#669933"/>
  120. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  121. <LinearLayout
  122.     xmlns:android="http://schemas.android.com/apk/res/android"
  123.     xmlns:tools="http://schemas.android.com/tools"
  124.     android:layout_width="match_parent"
  125.     android:layout_height="match_parent"
  126.     tools:context=".MainActivity"
  127.     android:orientation="vertical"
  128.     android:gravity="center"
  129.     android:background="#FFFFFF"
  130.     android:id="@+id/parent">
  131.     <TextView
  132.         android:layout_width="wrap_content"
  133.         android:layout_height="wrap_content"
  134.         android:text="Hello World"
  135.         android:textSize="60sp"
  136.         android:textColor="#669933"/>
  137. </LinearLayout>this.mContext = context;<?xml version="1.0" encoding="utf-8"?>
  138. <LinearLayout
  139.     xmlns:android="http://schemas.android.com/apk/res/android"
  140.     xmlns:tools="http://schemas.android.com/tools"
  141.     android:layout_width="match_parent"
  142.     android:layout_height="match_parent"
  143.     tools:context=".MainActivity"
  144.     android:orientation="vertical"
  145.     android:gravity="center"
  146.     android:background="#FFFFFF"
  147.     android:id="@+id/parent">
  148.     <TextView
  149.         android:layout_width="wrap_content"
  150.         android:layout_height="wrap_content"
  151.         android:text="Hello World"
  152.         android:textSize="60sp"
  153.         android:textColor="#669933"/>
  154. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  155. <LinearLayout
  156.     xmlns:android="http://schemas.android.com/apk/res/android"
  157.     xmlns:tools="http://schemas.android.com/tools"
  158.     android:layout_width="match_parent"
  159.     android:layout_height="match_parent"
  160.     tools:context=".MainActivity"
  161.     android:orientation="vertical"
  162.     android:gravity="center"
  163.     android:background="#FFFFFF"
  164.     android:id="@+id/parent">
  165.     <TextView
  166.         android:layout_width="wrap_content"
  167.         android:layout_height="wrap_content"
  168.         android:text="Hello World"
  169.         android:textSize="60sp"
  170.         android:textColor="#669933"/>
  171. </LinearLayout>@Override<?xml version="1.0" encoding="utf-8"?>
  172. <LinearLayout
  173.     xmlns:android="http://schemas.android.com/apk/res/android"
  174.     xmlns:tools="http://schemas.android.com/tools"
  175.     android:layout_width="match_parent"
  176.     android:layout_height="match_parent"
  177.     tools:context=".MainActivity"
  178.     android:orientation="vertical"
  179.     android:gravity="center"
  180.     android:background="#FFFFFF"
  181.     android:id="@+id/parent">
  182.     <TextView
  183.         android:layout_width="wrap_content"
  184.         android:layout_height="wrap_content"
  185.         android:text="Hello World"
  186.         android:textSize="60sp"
  187.         android:textColor="#669933"/>
  188. </LinearLayout>public RuntimeShader onSurfaceCreated() {<?xml version="1.0" encoding="utf-8"?>
  189. <LinearLayout
  190.     xmlns:android="http://schemas.android.com/apk/res/android"
  191.     xmlns:tools="http://schemas.android.com/tools"
  192.     android:layout_width="match_parent"
  193.     android:layout_height="match_parent"
  194.     tools:context=".MainActivity"
  195.     android:orientation="vertical"
  196.     android:gravity="center"
  197.     android:background="#FFFFFF"
  198.     android:id="@+id/parent">
  199.     <TextView
  200.         android:layout_width="wrap_content"
  201.         android:layout_height="wrap_content"
  202.         android:text="Hello World"
  203.         android:textSize="60sp"
  204.         android:textColor="#669933"/>
  205. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  206. <LinearLayout
  207.     xmlns:android="http://schemas.android.com/apk/res/android"
  208.     xmlns:tools="http://schemas.android.com/tools"
  209.     android:layout_width="match_parent"
  210.     android:layout_height="match_parent"
  211.     tools:context=".MainActivity"
  212.     android:orientation="vertical"
  213.     android:gravity="center"
  214.     android:background="#FFFFFF"
  215.     android:id="@+id/parent">
  216.     <TextView
  217.         android:layout_width="wrap_content"
  218.         android:layout_height="wrap_content"
  219.         android:text="Hello World"
  220.         android:textSize="60sp"
  221.         android:textColor="#669933"/>
  222. </LinearLayout>String shaderCode1 = StringUtils.loadString(mContext, "shaders/dispersion.agsl");<?xml version="1.0" encoding="utf-8"?>
  223. <LinearLayout
  224.     xmlns:android="http://schemas.android.com/apk/res/android"
  225.     xmlns:tools="http://schemas.android.com/tools"
  226.     android:layout_width="match_parent"
  227.     android:layout_height="match_parent"
  228.     tools:context=".MainActivity"
  229.     android:orientation="vertical"
  230.     android:gravity="center"
  231.     android:background="#FFFFFF"
  232.     android:id="@+id/parent">
  233.     <TextView
  234.         android:layout_width="wrap_content"
  235.         android:layout_height="wrap_content"
  236.         android:text="Hello World"
  237.         android:textSize="60sp"
  238.         android:textColor="#669933"/>
  239. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  240. <LinearLayout
  241.     xmlns:android="http://schemas.android.com/apk/res/android"
  242.     xmlns:tools="http://schemas.android.com/tools"
  243.     android:layout_width="match_parent"
  244.     android:layout_height="match_parent"
  245.     tools:context=".MainActivity"
  246.     android:orientation="vertical"
  247.     android:gravity="center"
  248.     android:background="#FFFFFF"
  249.     android:id="@+id/parent">
  250.     <TextView
  251.         android:layout_width="wrap_content"
  252.         android:layout_height="wrap_content"
  253.         android:text="Hello World"
  254.         android:textSize="60sp"
  255.         android:textColor="#669933"/>
  256. </LinearLayout>mShader1 = new RuntimeShader(shaderCode1);<?xml version="1.0" encoding="utf-8"?>
  257. <LinearLayout
  258.     xmlns:android="http://schemas.android.com/apk/res/android"
  259.     xmlns:tools="http://schemas.android.com/tools"
  260.     android:layout_width="match_parent"
  261.     android:layout_height="match_parent"
  262.     tools:context=".MainActivity"
  263.     android:orientation="vertical"
  264.     android:gravity="center"
  265.     android:background="#FFFFFF"
  266.     android:id="@+id/parent">
  267.     <TextView
  268.         android:layout_width="wrap_content"
  269.         android:layout_height="wrap_content"
  270.         android:text="Hello World"
  271.         android:textSize="60sp"
  272.         android:textColor="#669933"/>
  273. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  274. <LinearLayout
  275.     xmlns:android="http://schemas.android.com/apk/res/android"
  276.     xmlns:tools="http://schemas.android.com/tools"
  277.     android:layout_width="match_parent"
  278.     android:layout_height="match_parent"
  279.     tools:context=".MainActivity"
  280.     android:orientation="vertical"
  281.     android:gravity="center"
  282.     android:background="#FFFFFF"
  283.     android:id="@+id/parent">
  284.     <TextView
  285.         android:layout_width="wrap_content"
  286.         android:layout_height="wrap_content"
  287.         android:text="Hello World"
  288.         android:textSize="60sp"
  289.         android:textColor="#669933"/>
  290. </LinearLayout>String shaderCode2 = StringUtils.loadString(mContext, "shaders/jelly.agsl");<?xml version="1.0" encoding="utf-8"?>
  291. <LinearLayout
  292.     xmlns:android="http://schemas.android.com/apk/res/android"
  293.     xmlns:tools="http://schemas.android.com/tools"
  294.     android:layout_width="match_parent"
  295.     android:layout_height="match_parent"
  296.     tools:context=".MainActivity"
  297.     android:orientation="vertical"
  298.     android:gravity="center"
  299.     android:background="#FFFFFF"
  300.     android:id="@+id/parent">
  301.     <TextView
  302.         android:layout_width="wrap_content"
  303.         android:layout_height="wrap_content"
  304.         android:text="Hello World"
  305.         android:textSize="60sp"
  306.         android:textColor="#669933"/>
  307. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  308. <LinearLayout
  309.     xmlns:android="http://schemas.android.com/apk/res/android"
  310.     xmlns:tools="http://schemas.android.com/tools"
  311.     android:layout_width="match_parent"
  312.     android:layout_height="match_parent"
  313.     tools:context=".MainActivity"
  314.     android:orientation="vertical"
  315.     android:gravity="center"
  316.     android:background="#FFFFFF"
  317.     android:id="@+id/parent">
  318.     <TextView
  319.         android:layout_width="wrap_content"
  320.         android:layout_height="wrap_content"
  321.         android:text="Hello World"
  322.         android:textSize="60sp"
  323.         android:textColor="#669933"/>
  324. </LinearLayout>mShader2 = new RuntimeShader(shaderCode2);<?xml version="1.0" encoding="utf-8"?>
  325. <LinearLayout
  326.     xmlns:android="http://schemas.android.com/apk/res/android"
  327.     xmlns:tools="http://schemas.android.com/tools"
  328.     android:layout_width="match_parent"
  329.     android:layout_height="match_parent"
  330.     tools:context=".MainActivity"
  331.     android:orientation="vertical"
  332.     android:gravity="center"
  333.     android:background="#FFFFFF"
  334.     android:id="@+id/parent">
  335.     <TextView
  336.         android:layout_width="wrap_content"
  337.         android:layout_height="wrap_content"
  338.         android:text="Hello World"
  339.         android:textSize="60sp"
  340.         android:textColor="#669933"/>
  341. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  342. <LinearLayout
  343.     xmlns:android="http://schemas.android.com/apk/res/android"
  344.     xmlns:tools="http://schemas.android.com/tools"
  345.     android:layout_width="match_parent"
  346.     android:layout_height="match_parent"
  347.     tools:context=".MainActivity"
  348.     android:orientation="vertical"
  349.     android:gravity="center"
  350.     android:background="#FFFFFF"
  351.     android:id="@+id/parent">
  352.     <TextView
  353.         android:layout_width="wrap_content"
  354.         android:layout_height="wrap_content"
  355.         android:text="Hello World"
  356.         android:textSize="60sp"
  357.         android:textColor="#669933"/>
  358. </LinearLayout>mBitmapTexture = BitmapTexture.create(mContext, "textures/photo.jpg");<?xml version="1.0" encoding="utf-8"?>
  359. <LinearLayout
  360.     xmlns:android="http://schemas.android.com/apk/res/android"
  361.     xmlns:tools="http://schemas.android.com/tools"
  362.     android:layout_width="match_parent"
  363.     android:layout_height="match_parent"
  364.     tools:context=".MainActivity"
  365.     android:orientation="vertical"
  366.     android:gravity="center"
  367.     android:background="#FFFFFF"
  368.     android:id="@+id/parent">
  369.     <TextView
  370.         android:layout_width="wrap_content"
  371.         android:layout_height="wrap_content"
  372.         android:text="Hello World"
  373.         android:textSize="60sp"
  374.         android:textColor="#669933"/>
  375. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  376. <LinearLayout
  377.     xmlns:android="http://schemas.android.com/apk/res/android"
  378.     xmlns:tools="http://schemas.android.com/tools"
  379.     android:layout_width="match_parent"
  380.     android:layout_height="match_parent"
  381.     tools:context=".MainActivity"
  382.     android:orientation="vertical"
  383.     android:gravity="center"
  384.     android:background="#FFFFFF"
  385.     android:id="@+id/parent">
  386.     <TextView
  387.         android:layout_width="wrap_content"
  388.         android:layout_height="wrap_content"
  389.         android:text="Hello World"
  390.         android:textSize="60sp"
  391.         android:textColor="#669933"/>
  392. </LinearLayout>return mShader2;<?xml version="1.0" encoding="utf-8"?>
  393. <LinearLayout
  394.     xmlns:android="http://schemas.android.com/apk/res/android"
  395.     xmlns:tools="http://schemas.android.com/tools"
  396.     android:layout_width="match_parent"
  397.     android:layout_height="match_parent"
  398.     tools:context=".MainActivity"
  399.     android:orientation="vertical"
  400.     android:gravity="center"
  401.     android:background="#FFFFFF"
  402.     android:id="@+id/parent">
  403.     <TextView
  404.         android:layout_width="wrap_content"
  405.         android:layout_height="wrap_content"
  406.         android:text="Hello World"
  407.         android:textSize="60sp"
  408.         android:textColor="#669933"/>
  409. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  410. <LinearLayout
  411.     xmlns:android="http://schemas.android.com/apk/res/android"
  412.     xmlns:tools="http://schemas.android.com/tools"
  413.     android:layout_width="match_parent"
  414.     android:layout_height="match_parent"
  415.     tools:context=".MainActivity"
  416.     android:orientation="vertical"
  417.     android:gravity="center"
  418.     android:background="#FFFFFF"
  419.     android:id="@+id/parent">
  420.     <TextView
  421.         android:layout_width="wrap_content"
  422.         android:layout_height="wrap_content"
  423.         android:text="Hello World"
  424.         android:textSize="60sp"
  425.         android:textColor="#669933"/>
  426. </LinearLayout>@Override<?xml version="1.0" encoding="utf-8"?>
  427. <LinearLayout
  428.     xmlns:android="http://schemas.android.com/apk/res/android"
  429.     xmlns:tools="http://schemas.android.com/tools"
  430.     android:layout_width="match_parent"
  431.     android:layout_height="match_parent"
  432.     tools:context=".MainActivity"
  433.     android:orientation="vertical"
  434.     android:gravity="center"
  435.     android:background="#FFFFFF"
  436.     android:id="@+id/parent">
  437.     <TextView
  438.         android:layout_width="wrap_content"
  439.         android:layout_height="wrap_content"
  440.         android:text="Hello World"
  441.         android:textSize="60sp"
  442.         android:textColor="#669933"/>
  443. </LinearLayout>public void onSurfaceChanged(int width, int height) {<?xml version="1.0" encoding="utf-8"?>
  444. <LinearLayout
  445.     xmlns:android="http://schemas.android.com/apk/res/android"
  446.     xmlns:tools="http://schemas.android.com/tools"
  447.     android:layout_width="match_parent"
  448.     android:layout_height="match_parent"
  449.     tools:context=".MainActivity"
  450.     android:orientation="vertical"
  451.     android:gravity="center"
  452.     android:background="#FFFFFF"
  453.     android:id="@+id/parent">
  454.     <TextView
  455.         android:layout_width="wrap_content"
  456.         android:layout_height="wrap_content"
  457.         android:text="Hello World"
  458.         android:textSize="60sp"
  459.         android:textColor="#669933"/>
  460. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  461. <LinearLayout
  462.     xmlns:android="http://schemas.android.com/apk/res/android"
  463.     xmlns:tools="http://schemas.android.com/tools"
  464.     android:layout_width="match_parent"
  465.     android:layout_height="match_parent"
  466.     tools:context=".MainActivity"
  467.     android:orientation="vertical"
  468.     android:gravity="center"
  469.     android:background="#FFFFFF"
  470.     android:id="@+id/parent">
  471.     <TextView
  472.         android:layout_width="wrap_content"
  473.         android:layout_height="wrap_content"
  474.         android:text="Hello World"
  475.         android:textSize="60sp"
  476.         android:textColor="#669933"/>
  477. </LinearLayout>mResolution = new float[] { width, height };<?xml version="1.0" encoding="utf-8"?>
  478. <LinearLayout
  479.     xmlns:android="http://schemas.android.com/apk/res/android"
  480.     xmlns:tools="http://schemas.android.com/tools"
  481.     android:layout_width="match_parent"
  482.     android:layout_height="match_parent"
  483.     tools:context=".MainActivity"
  484.     android:orientation="vertical"
  485.     android:gravity="center"
  486.     android:background="#FFFFFF"
  487.     android:id="@+id/parent">
  488.     <TextView
  489.         android:layout_width="wrap_content"
  490.         android:layout_height="wrap_content"
  491.         android:text="Hello World"
  492.         android:textSize="60sp"
  493.         android:textColor="#669933"/>
  494. </LinearLayout>}<?xml version="1.0" encoding="utf-8"?>
  495. <LinearLayout
  496.     xmlns:android="http://schemas.android.com/apk/res/android"
  497.     xmlns:tools="http://schemas.android.com/tools"
  498.     android:layout_width="match_parent"
  499.     android:layout_height="match_parent"
  500.     tools:context=".MainActivity"
  501.     android:orientation="vertical"
  502.     android:gravity="center"
  503.     android:background="#FFFFFF"
  504.     android:id="@+id/parent">
  505.     <TextView
  506.         android:layout_width="wrap_content"
  507.         android:layout_height="wrap_content"
  508.         android:text="Hello World"
  509.         android:textSize="60sp"
  510.         android:textColor="#669933"/>
  511. </LinearLayout>@Override<?xml version="1.0" encoding="utf-8"?>
  512. <LinearLayout
  513.     xmlns:android="http://schemas.android.com/apk/res/android"
  514.     xmlns:tools="http://schemas.android.com/tools"
  515.     android:layout_width="match_parent"
  516.     android:layout_height="match_parent"
  517.     tools:context=".MainActivity"
  518.     android:orientation="vertical"
  519.     android:gravity="center"
  520.     android:background="#FFFFFF"
  521.     android:id="@+id/parent">
  522.     <TextView
  523.         android:layout_width="wrap_content"
  524.         android:layout_height="wrap_content"
  525.         android:text="Hello World"
  526.         android:textSize="60sp"
  527.         android:textColor="#669933"/>
  528. </LinearLayout>public void onDrawFrame(long runTime) {<?xml version="1.0" encoding="utf-8"?>
  529. <LinearLayout
  530.     xmlns:android="http://schemas.android.com/apk/res/android"
  531.     xmlns:tools="http://schemas.android.com/tools"
  532.     android:layout_width="match_parent"
  533.     android:layout_height="match_parent"
  534.     tools:context=".MainActivity"
  535.     android:orientation="vertical"
  536.     android:gravity="center"
  537.     android:background="#FFFFFF"
  538.     android:id="@+id/parent">
  539.     <TextView
  540.         android:layout_width="wrap_content"
  541.         android:layout_height="wrap_content"
  542.         android:text="Hello World"
  543.         android:textSize="60sp"
  544.         android:textColor="#669933"/>
  545. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  546. <LinearLayout
  547.     xmlns:android="http://schemas.android.com/apk/res/android"
  548.     xmlns:tools="http://schemas.android.com/tools"
  549.     android:layout_width="match_parent"
  550.     android:layout_height="match_parent"
  551.     tools:context=".MainActivity"
  552.     android:orientation="vertical"
  553.     android:gravity="center"
  554.     android:background="#FFFFFF"
  555.     android:id="@+id/parent">
  556.     <TextView
  557.         android:layout_width="wrap_content"
  558.         android:layout_height="wrap_content"
  559.         android:text="Hello World"
  560.         android:textSize="60sp"
  561.         android:textColor="#669933"/>
  562. </LinearLayout>mBitmapTexture.bind(mShader1, "u_texture", "u_textureSize");<?xml version="1.0" encoding="utf-8"?>
  563. <LinearLayout
  564.     xmlns:android="http://schemas.android.com/apk/res/android"
  565.     xmlns:tools="http://schemas.android.com/tools"
  566.     android:layout_width="match_parent"
  567.     android:layout_height="match_parent"
  568.     tools:context=".MainActivity"
  569.     android:orientation="vertical"
  570.     android:gravity="center"
  571.     android:background="#FFFFFF"
  572.     android:id="@+id/parent">
  573.     <TextView
  574.         android:layout_width="wrap_content"
  575.         android:layout_height="wrap_content"
  576.         android:text="Hello World"
  577.         android:textSize="60sp"
  578.         android:textColor="#669933"/>
  579. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  580. <LinearLayout
  581.     xmlns:android="http://schemas.android.com/apk/res/android"
  582.     xmlns:tools="http://schemas.android.com/tools"
  583.     android:layout_width="match_parent"
  584.     android:layout_height="match_parent"
  585.     tools:context=".MainActivity"
  586.     android:orientation="vertical"
  587.     android:gravity="center"
  588.     android:background="#FFFFFF"
  589.     android:id="@+id/parent">
  590.     <TextView
  591.         android:layout_width="wrap_content"
  592.         android:layout_height="wrap_content"
  593.         android:text="Hello World"
  594.         android:textSize="60sp"
  595.         android:textColor="#669933"/>
  596. </LinearLayout>mShader1.setFloatUniform("u_resolution", mResolution);<?xml version="1.0" encoding="utf-8"?>
  597. <LinearLayout
  598.     xmlns:android="http://schemas.android.com/apk/res/android"
  599.     xmlns:tools="http://schemas.android.com/tools"
  600.     android:layout_width="match_parent"
  601.     android:layout_height="match_parent"
  602.     tools:context=".MainActivity"
  603.     android:orientation="vertical"
  604.     android:gravity="center"
  605.     android:background="#FFFFFF"
  606.     android:id="@+id/parent">
  607.     <TextView
  608.         android:layout_width="wrap_content"
  609.         android:layout_height="wrap_content"
  610.         android:text="Hello World"
  611.         android:textSize="60sp"
  612.         android:textColor="#669933"/>
  613. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  614. <LinearLayout
  615.     xmlns:android="http://schemas.android.com/apk/res/android"
  616.     xmlns:tools="http://schemas.android.com/tools"
  617.     android:layout_width="match_parent"
  618.     android:layout_height="match_parent"
  619.     tools:context=".MainActivity"
  620.     android:orientation="vertical"
  621.     android:gravity="center"
  622.     android:background="#FFFFFF"
  623.     android:id="@+id/parent">
  624.     <TextView
  625.         android:layout_width="wrap_content"
  626.         android:layout_height="wrap_content"
  627.         android:text="Hello World"
  628.         android:textSize="60sp"
  629.         android:textColor="#669933"/>
  630. </LinearLayout>mShader1.setFloatUniform("u_time", runTime / 1000f);<?xml version="1.0" encoding="utf-8"?>
  631. <LinearLayout
  632.     xmlns:android="http://schemas.android.com/apk/res/android"
  633.     xmlns:tools="http://schemas.android.com/tools"
  634.     android:layout_width="match_parent"
  635.     android:layout_height="match_parent"
  636.     tools:context=".MainActivity"
  637.     android:orientation="vertical"
  638.     android:gravity="center"
  639.     android:background="#FFFFFF"
  640.     android:id="@+id/parent">
  641.     <TextView
  642.         android:layout_width="wrap_content"
  643.         android:layout_height="wrap_content"
  644.         android:text="Hello World"
  645.         android:textSize="60sp"
  646.         android:textColor="#669933"/>
  647. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  648. <LinearLayout
  649.     xmlns:android="http://schemas.android.com/apk/res/android"
  650.     xmlns:tools="http://schemas.android.com/tools"
  651.     android:layout_width="match_parent"
  652.     android:layout_height="match_parent"
  653.     tools:context=".MainActivity"
  654.     android:orientation="vertical"
  655.     android:gravity="center"
  656.     android:background="#FFFFFF"
  657.     android:id="@+id/parent">
  658.     <TextView
  659.         android:layout_width="wrap_content"
  660.         android:layout_height="wrap_content"
  661.         android:text="Hello World"
  662.         android:textSize="60sp"
  663.         android:textColor="#669933"/>
  664. </LinearLayout>mShader2.setInputShader("u_texture", mShader1);<?xml version="1.0" encoding="utf-8"?>
  665. <LinearLayout
  666.     xmlns:android="http://schemas.android.com/apk/res/android"
  667.     xmlns:tools="http://schemas.android.com/tools"
  668.     android:layout_width="match_parent"
  669.     android:layout_height="match_parent"
  670.     tools:context=".MainActivity"
  671.     android:orientation="vertical"
  672.     android:gravity="center"
  673.     android:background="#FFFFFF"
  674.     android:id="@+id/parent">
  675.     <TextView
  676.         android:layout_width="wrap_content"
  677.         android:layout_height="wrap_content"
  678.         android:text="Hello World"
  679.         android:textSize="60sp"
  680.         android:textColor="#669933"/>
  681. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  682. <LinearLayout
  683.     xmlns:android="http://schemas.android.com/apk/res/android"
  684.     xmlns:tools="http://schemas.android.com/tools"
  685.     android:layout_width="match_parent"
  686.     android:layout_height="match_parent"
  687.     tools:context=".MainActivity"
  688.     android:orientation="vertical"
  689.     android:gravity="center"
  690.     android:background="#FFFFFF"
  691.     android:id="@+id/parent">
  692.     <TextView
  693.         android:layout_width="wrap_content"
  694.         android:layout_height="wrap_content"
  695.         android:text="Hello World"
  696.         android:textSize="60sp"
  697.         android:textColor="#669933"/>
  698. </LinearLayout>mShader2.setFloatUniform("u_textureSize", mResolution);<?xml version="1.0" encoding="utf-8"?>
  699. <LinearLayout
  700.     xmlns:android="http://schemas.android.com/apk/res/android"
  701.     xmlns:tools="http://schemas.android.com/tools"
  702.     android:layout_width="match_parent"
  703.     android:layout_height="match_parent"
  704.     tools:context=".MainActivity"
  705.     android:orientation="vertical"
  706.     android:gravity="center"
  707.     android:background="#FFFFFF"
  708.     android:id="@+id/parent">
  709.     <TextView
  710.         android:layout_width="wrap_content"
  711.         android:layout_height="wrap_content"
  712.         android:text="Hello World"
  713.         android:textSize="60sp"
  714.         android:textColor="#669933"/>
  715. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  716. <LinearLayout
  717.     xmlns:android="http://schemas.android.com/apk/res/android"
  718.     xmlns:tools="http://schemas.android.com/tools"
  719.     android:layout_width="match_parent"
  720.     android:layout_height="match_parent"
  721.     tools:context=".MainActivity"
  722.     android:orientation="vertical"
  723.     android:gravity="center"
  724.     android:background="#FFFFFF"
  725.     android:id="@+id/parent">
  726.     <TextView
  727.         android:layout_width="wrap_content"
  728.         android:layout_height="wrap_content"
  729.         android:text="Hello World"
  730.         android:textSize="60sp"
  731.         android:textColor="#669933"/>
  732. </LinearLayout>mShader2.setFloatUniform("u_resolution", mResolution);<?xml version="1.0" encoding="utf-8"?>
  733. <LinearLayout
  734.     xmlns:android="http://schemas.android.com/apk/res/android"
  735.     xmlns:tools="http://schemas.android.com/tools"
  736.     android:layout_width="match_parent"
  737.     android:layout_height="match_parent"
  738.     tools:context=".MainActivity"
  739.     android:orientation="vertical"
  740.     android:gravity="center"
  741.     android:background="#FFFFFF"
  742.     android:id="@+id/parent">
  743.     <TextView
  744.         android:layout_width="wrap_content"
  745.         android:layout_height="wrap_content"
  746.         android:text="Hello World"
  747.         android:textSize="60sp"
  748.         android:textColor="#669933"/>
  749. </LinearLayout><?xml version="1.0" encoding="utf-8"?>
  750. <LinearLayout
  751.     xmlns:android="http://schemas.android.com/apk/res/android"
  752.     xmlns:tools="http://schemas.android.com/tools"
  753.     android:layout_width="match_parent"
  754.     android:layout_height="match_parent"
  755.     tools:context=".MainActivity"
  756.     android:orientation="vertical"
  757.     android:gravity="center"
  758.     android:background="#FFFFFF"
  759.     android:id="@+id/parent">
  760.     <TextView
  761.         android:layout_width="wrap_content"
  762.         android:layout_height="wrap_content"
  763.         android:text="Hello World"
  764.         android:textSize="60sp"
  765.         android:textColor="#669933"/>
  766. </LinearLayout>mShader2.setFloatUniform("u_time", runTime / 1000f);<?xml version="1.0" encoding="utf-8"?>
  767. <LinearLayout
  768.     xmlns:android="http://schemas.android.com/apk/res/android"
  769.     xmlns:tools="http://schemas.android.com/tools"
  770.     android:layout_width="match_parent"
  771.     android:layout_height="match_parent"
  772.     tools:context=".MainActivity"
  773.     android:orientation="vertical"
  774.     android:gravity="center"
  775.     android:background="#FFFFFF"
  776.     android:id="@+id/parent">
  777.     <TextView
  778.         android:layout_width="wrap_content"
  779.         android:layout_height="wrap_content"
  780.         android:text="Hello World"
  781.         android:textSize="60sp"
  782.         android:textColor="#669933"/>
  783. </LinearLayout>}}
复制代码
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>dispersion.agsl
  1. uniform shader u_texture;uniform vec2 u_textureSize;uniform vec2 u_resolution;uniform float u_time;vec4 texture(vec2 normUV) { // 纹理采样<?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     xmlns:tools="http://schemas.android.com/tools"
  5.     android:layout_width="match_parent"
  6.     android:layout_height="match_parent"
  7.     tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:gravity="center"
  10.     android:background="#FFFFFF"
  11.     android:id="@+id/parent">
  12.     <TextView
  13.         android:layout_width="wrap_content"
  14.         android:layout_height="wrap_content"
  15.         android:text="Hello World"
  16.         android:textSize="60sp"
  17.         android:textColor="#669933"/>
  18. </LinearLayout>vec2 uv = normUV * u_textureSize;<?xml version="1.0" encoding="utf-8"?>
  19. <LinearLayout
  20.     xmlns:android="http://schemas.android.com/apk/res/android"
  21.     xmlns:tools="http://schemas.android.com/tools"
  22.     android:layout_width="match_parent"
  23.     android:layout_height="match_parent"
  24.     tools:context=".MainActivity"
  25.     android:orientation="vertical"
  26.     android:gravity="center"
  27.     android:background="#FFFFFF"
  28.     android:id="@+id/parent">
  29.     <TextView
  30.         android:layout_width="wrap_content"
  31.         android:layout_height="wrap_content"
  32.         android:text="Hello World"
  33.         android:textSize="60sp"
  34.         android:textColor="#669933"/>
  35. </LinearLayout>return u_texture.eval(uv);}vec2 getOffset() { // 偏移函数<?xml version="1.0" encoding="utf-8"?>
  36. <LinearLayout
  37.     xmlns:android="http://schemas.android.com/apk/res/android"
  38.     xmlns:tools="http://schemas.android.com/tools"
  39.     android:layout_width="match_parent"
  40.     android:layout_height="match_parent"
  41.     tools:context=".MainActivity"
  42.     android:orientation="vertical"
  43.     android:gravity="center"
  44.     android:background="#FFFFFF"
  45.     android:id="@+id/parent">
  46.     <TextView
  47.         android:layout_width="wrap_content"
  48.         android:layout_height="wrap_content"
  49.         android:text="Hello World"
  50.         android:textSize="60sp"
  51.         android:textColor="#669933"/>
  52. </LinearLayout>float time = u_time * 1.5;<?xml version="1.0" encoding="utf-8"?>
  53. <LinearLayout
  54.     xmlns:android="http://schemas.android.com/apk/res/android"
  55.     xmlns:tools="http://schemas.android.com/tools"
  56.     android:layout_width="match_parent"
  57.     android:layout_height="match_parent"
  58.     tools:context=".MainActivity"
  59.     android:orientation="vertical"
  60.     android:gravity="center"
  61.     android:background="#FFFFFF"
  62.     android:id="@+id/parent">
  63.     <TextView
  64.         android:layout_width="wrap_content"
  65.         android:layout_height="wrap_content"
  66.         android:text="Hello World"
  67.         android:textSize="60sp"
  68.         android:textColor="#669933"/>
  69. </LinearLayout>vec2 dire = vec2(sin(time), cos(time));<?xml version="1.0" encoding="utf-8"?>
  70. <LinearLayout
  71.     xmlns:android="http://schemas.android.com/apk/res/android"
  72.     xmlns:tools="http://schemas.android.com/tools"
  73.     android:layout_width="match_parent"
  74.     android:layout_height="match_parent"
  75.     tools:context=".MainActivity"
  76.     android:orientation="vertical"
  77.     android:gravity="center"
  78.     android:background="#FFFFFF"
  79.     android:id="@+id/parent">
  80.     <TextView
  81.         android:layout_width="wrap_content"
  82.         android:layout_height="wrap_content"
  83.         android:text="Hello World"
  84.         android:textSize="60sp"
  85.         android:textColor="#669933"/>
  86. </LinearLayout>float strength = sin(u_time * 2.0) * 0.01;<?xml version="1.0" encoding="utf-8"?>
  87. <LinearLayout
  88.     xmlns:android="http://schemas.android.com/apk/res/android"
  89.     xmlns:tools="http://schemas.android.com/tools"
  90.     android:layout_width="match_parent"
  91.     android:layout_height="match_parent"
  92.     tools:context=".MainActivity"
  93.     android:orientation="vertical"
  94.     android:gravity="center"
  95.     android:background="#FFFFFF"
  96.     android:id="@+id/parent">
  97.     <TextView
  98.         android:layout_width="wrap_content"
  99.         android:layout_height="wrap_content"
  100.         android:text="Hello World"
  101.         android:textSize="60sp"
  102.         android:textColor="#669933"/>
  103. </LinearLayout>return dire * strength;}vec4 main(vec2 coords) {<?xml version="1.0" encoding="utf-8"?>
  104. <LinearLayout
  105.     xmlns:android="http://schemas.android.com/apk/res/android"
  106.     xmlns:tools="http://schemas.android.com/tools"
  107.     android:layout_width="match_parent"
  108.     android:layout_height="match_parent"
  109.     tools:context=".MainActivity"
  110.     android:orientation="vertical"
  111.     android:gravity="center"
  112.     android:background="#FFFFFF"
  113.     android:id="@+id/parent">
  114.     <TextView
  115.         android:layout_width="wrap_content"
  116.         android:layout_height="wrap_content"
  117.         android:text="Hello World"
  118.         android:textSize="60sp"
  119.         android:textColor="#669933"/>
  120. </LinearLayout>vec2 normUV = coords / u_resolution;<?xml version="1.0" encoding="utf-8"?>
  121. <LinearLayout
  122.     xmlns:android="http://schemas.android.com/apk/res/android"
  123.     xmlns:tools="http://schemas.android.com/tools"
  124.     android:layout_width="match_parent"
  125.     android:layout_height="match_parent"
  126.     tools:context=".MainActivity"
  127.     android:orientation="vertical"
  128.     android:gravity="center"
  129.     android:background="#FFFFFF"
  130.     android:id="@+id/parent">
  131.     <TextView
  132.         android:layout_width="wrap_content"
  133.         android:layout_height="wrap_content"
  134.         android:text="Hello World"
  135.         android:textSize="60sp"
  136.         android:textColor="#669933"/>
  137. </LinearLayout>vec4 color = texture(normUV);<?xml version="1.0" encoding="utf-8"?>
  138. <LinearLayout
  139.     xmlns:android="http://schemas.android.com/apk/res/android"
  140.     xmlns:tools="http://schemas.android.com/tools"
  141.     android:layout_width="match_parent"
  142.     android:layout_height="match_parent"
  143.     tools:context=".MainActivity"
  144.     android:orientation="vertical"
  145.     android:gravity="center"
  146.     android:background="#FFFFFF"
  147.     android:id="@+id/parent">
  148.     <TextView
  149.         android:layout_width="wrap_content"
  150.         android:layout_height="wrap_content"
  151.         android:text="Hello World"
  152.         android:textSize="60sp"
  153.         android:textColor="#669933"/>
  154. </LinearLayout>vec2 offset = getOffset();<?xml version="1.0" encoding="utf-8"?>
  155. <LinearLayout
  156.     xmlns:android="http://schemas.android.com/apk/res/android"
  157.     xmlns:tools="http://schemas.android.com/tools"
  158.     android:layout_width="match_parent"
  159.     android:layout_height="match_parent"
  160.     tools:context=".MainActivity"
  161.     android:orientation="vertical"
  162.     android:gravity="center"
  163.     android:background="#FFFFFF"
  164.     android:id="@+id/parent">
  165.     <TextView
  166.         android:layout_width="wrap_content"
  167.         android:layout_height="wrap_content"
  168.         android:text="Hello World"
  169.         android:textSize="60sp"
  170.         android:textColor="#669933"/>
  171. </LinearLayout>color.r = texture(normUV + offset).r;<?xml version="1.0" encoding="utf-8"?>
  172. <LinearLayout
  173.     xmlns:android="http://schemas.android.com/apk/res/android"
  174.     xmlns:tools="http://schemas.android.com/tools"
  175.     android:layout_width="match_parent"
  176.     android:layout_height="match_parent"
  177.     tools:context=".MainActivity"
  178.     android:orientation="vertical"
  179.     android:gravity="center"
  180.     android:background="#FFFFFF"
  181.     android:id="@+id/parent">
  182.     <TextView
  183.         android:layout_width="wrap_content"
  184.         android:layout_height="wrap_content"
  185.         android:text="Hello World"
  186.         android:textSize="60sp"
  187.         android:textColor="#669933"/>
  188. </LinearLayout>color.b = texture(normUV - offset).b;<?xml version="1.0" encoding="utf-8"?>
  189. <LinearLayout
  190.     xmlns:android="http://schemas.android.com/apk/res/android"
  191.     xmlns:tools="http://schemas.android.com/tools"
  192.     android:layout_width="match_parent"
  193.     android:layout_height="match_parent"
  194.     tools:context=".MainActivity"
  195.     android:orientation="vertical"
  196.     android:gravity="center"
  197.     android:background="#FFFFFF"
  198.     android:id="@+id/parent">
  199.     <TextView
  200.         android:layout_width="wrap_content"
  201.         android:layout_height="wrap_content"
  202.         android:text="Hello World"
  203.         android:textSize="60sp"
  204.         android:textColor="#669933"/>
  205. </LinearLayout>return color;}
复制代码
​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>运行效果如下,可以看到叠加了果冻畸变和 RGB 色散效果。
3.gif

​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:gravity="center"
    android:background="#FFFFFF"
    android:id="@+id/parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"
        android:textSize="60sp"
        android:textColor="#669933"/>

</LinearLayout>声明:本文转自【Android】RuntimeShader 应用。

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册