Android グラフィック シェーディング言語(AGSL)
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Android グラフィック シェーディング言語(AGSL)は、Android 13 以降でプログラム可能な RuntimeShader
オブジェクトの動作を定義するために使用されます。AGSL は、その構文の多くを GLSL フラグメント シェーダーと共有しますが、Android グラフィック レンダリング システム内で機能し、Canvas
内のペイントのカスタマイズと View
コンテンツのフィルタリングを行います。
運用理論
AGSL エフェクトは、より大規模な Android グラフィック パイプラインの一部として存在します。Android は、GPU アクセラレーションによる描画オペレーションを実行すると、必要な処理を実行するために単一の GPU フラグメント シェーダーをアセンブルします。通常、このシェーダーには複数のピースが含まれています。
たとえば、次のような情報です。
- ピクセルが描画されるシェイプの内側か外側か(または、アンチ エイリアスを適用する可能性のある境界上)にあるかを評価します。
- ピクセルがクリッピング領域の内側か外側にあるかを評価します(これもまた、境界ピクセルのアンチ エイリアス ロジックの可能性あり)。
Paint
の Shader
のロジック。シェーダーは、実際にはオブジェクトのツリーにすることができます(ComposeShader
と、以下で説明するその他の機能により)。
ColorFilter
についても同様のロジックを使用します。
- 統合コード(特定のタイプの
BlendMode
用)。
- Android のカラー マネージメントの一部である色空間変換コード。
Paint
の Shader
、ColorFilter
、または BlendMode
フィールドにオブジェクトの複雑なツリーがある場合でも、GPU フラグメント シェーダーは 1 つだけです。そのツリー内の各ノードが単一の関数を作成します。クリッピング コードとジオメトリ コードそれぞれで関数を作成します。ブレンディングのコードで関数を作成することもできます。その後、フラグメント シェーダー全体がこれらの関数をすべて呼び出します(シェーダー ツリーなどでは、他の関数を呼び出すことができます)。
AGSL 効果は、GPU のフラグメント シェーダーに 1 つまたは複数の関数を提供します。
基本的な構文
AGSL(および GLSL)は、C スタイルのドメイン固有言語です。bool
や int
などの型は C の同等のものを厳密に追跡します。ドメインの機能をサポートするベクトルと行列をサポートする追加の型があります。
修飾子は、シェーディング言語に固有の方法で精度ヒントの型に適用できます。if-else
ステートメントなどの制御構造は、C とよく似ています。この言語では switch
ステートメントと for
ループもサポートされています(制限付き)。制御構造によっては、コンパイル時に評価できる定数式が必要です。
AGSL は関数をサポートしています。すべてのシェーダー プログラムは main
関数から始まります。ユーザー定義関数はサポートされていますが、どのような再帰もサポートされていません。関数は「値リターン」呼び出し規則を使用します。関数に渡される値は、関数の呼び出し時にパラメータにコピーされ、出力はコピーされます。これは、in
、out
、inout
の修飾子によって決まります。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-26 UTC。
[null,null,["最終更新日 2025-07-26 UTC。"],[],[],null,["# Android Graphics Shading Language (AGSL) is used by Android 13 and above to\ndefine the behavior of programmable\n[`RuntimeShader`](/reference/android/graphics/RuntimeShader) objects. AGSL\nshares much of its syntax with GLSL fragment shaders, but works within the\nAndroid graphics rendering system to both customize painting within `Canvas`\nand filter `View` content.\n\nTheory of operation\n-------------------\n\nAGSL effects exist as part of the larger Android graphics pipeline. When Android\nissues a GPU accelerated drawing operation, it assembles a single GPU fragment\nshader to do the required work. This shader typically includes several pieces.\nFor example, it might include:\n\n- Evaluating whether a pixel falls inside or outside of the shape being drawn (or on the border, where it might apply anti-aliasing).\n- Evaluating whether a pixel falls inside or outside of the clipping region (again, with possible anti-aliasing logic for border pixels).\n- Logic for the [`Shader`](/reference/android/graphics/Shader) on the [`Paint`](/reference/android/graphics/Paint). The Shader can actually be a tree of objects (due to [`ComposeShader`](/reference/android/graphics/ComposeShader) and other features described below).\n- Similar logic for the [`ColorFilter`](/reference/android/graphics/ColorFilter).\n- Blending code (for certain types of [`BlendMode`](/reference/android/graphics/BlendMode)).\n- Color space conversion code, as part of Android's color management.\n- When the `Paint` has a complex tree of objects in the `Shader`, `ColorFilter`, or `BlendMode` fields, there is still only a single GPU fragment shader. Each node in that tree creates a single function. The clipping code and geometry code each create a function. The blending code might create a function. The overall fragment shader then calls all of these functions (which may call other functions, e.g. in the case of a shader tree).\n\nYour AGSL effect contributes a function (or functions) to the GPU's fragment shader.\n\nBasic syntax\n------------\n\nAGSL (and GLSL) are C-style domain specific languages. Types such as `bool` and\n`int` closely track their C equivalents; there are additional types to\nsupport vectors and matrices that support domain functionality.\n\nQualifiers can be applied to types for precision hints in a way that's unique to shading languages. Control structures such as `if-else` statements work much\nlike they do in C; the language also provides support for `switch` statements\nand `for` loops with limitations. Some control structures require constant expressions that can be evaluated at compile time.\n\nAGSL supports functions; every shader program begins with the `main` function.\nUser defined functions are supported, without support for recursion of any kind.\nFunctions use a \"value-return\" calling convention; values passed to functions are\ncopied into parameters when the function is called, and outputs are copied\nback; this is determined by the `in`, `out`, and `inout` qualifiers."]]