1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef skgpu_graphite_BuiltInCodeSnippetID_DEFINED 9 #define skgpu_graphite_BuiltInCodeSnippetID_DEFINED 10 11 #include "include/core/SkTypes.h" 12 13 namespace skgpu::graphite { 14 15 enum class BuiltInCodeSnippetID : int32_t { 16 // This isn't just a signal for a failure during paintparams key creation. It also actually 17 // implements the default behavior for an erroneous draw. Currently it just draws solid 18 // magenta. 19 kError, 20 21 // Snippet that passes through prior stage output 22 kPriorOutput, 23 24 // SkShader code snippets 25 kSolidColorShader, 26 kRGBPaintColor, 27 kAlphaOnlyPaintColor, 28 kLinearGradientShader4, 29 kLinearGradientShader8, 30 kLinearGradientShaderTexture, 31 kLinearGradientShaderBuffer, 32 kRadialGradientShader4, 33 kRadialGradientShader8, 34 kRadialGradientShaderTexture, 35 kRadialGradientShaderBuffer, 36 kSweepGradientShader4, 37 kSweepGradientShader8, 38 kSweepGradientShaderTexture, 39 kSweepGradientShaderBuffer, 40 kConicalGradientShader4, 41 kConicalGradientShader8, 42 kConicalGradientShaderTexture, 43 kConicalGradientShaderBuffer, 44 45 kLocalMatrixShader, 46 kLocalMatrixShaderPersp, 47 kImageShader, 48 kImageShaderClamp, 49 kCubicImageShader, 50 kHWImageShader, 51 kYUVImageShader, 52 kCubicYUVImageShader, 53 kHWYUVImageShader, 54 kHWYUVNoSwizzleImageShader, 55 kCoordClampShader, 56 kDitherShader, 57 kPerlinNoiseShader, 58 59 // SkColorFilter code snippets 60 kMatrixColorFilter, 61 kTableColorFilter, 62 kGaussianColorFilter, 63 64 // Color space transform snippet and its specializations 65 kColorSpaceXformColorFilter, 66 kColorSpaceXformPremul, 67 kColorSpaceXformSRGB, 68 69 // Emits special variable holding the primitiveColor emitted by a RenderStep 70 kPrimitiveColor, 71 72 // Analytic clip for circular roundrect and AA rect shapes 73 kAnalyticClip, 74 75 // Analytic plus atlas-based clip 76 kAnalyticAndAtlasClip, 77 78 kCompose, // compose 2 children together: outer_1(inner_0(...)) 79 kBlendCompose, // compose 3 children together: outer_2(inner_0(...), inner_1(...)) 80 81 // SkBlender code snippets 82 kPorterDuffBlender, // Can handle all GetPorterDuffBlendConstants() modes 83 kHSLCBlender, // kHue,kSaturation,kLuminosity, and kColor modes 84 // NOTE: We could offer an in-shader consolidation for overlay+hardlight, and darken+lighten 85 // but for now, those will map to the FixedBlends. 86 87 // Fixed blend modes hard code a specific blend function into the shader tree. This can be 88 // valuable when an internal effect is known to always do a certain blend and we want to 89 // benefit from inlining constants. It is also important for being able to convert the final 90 // blend of the SkPaint into fixed function HW blending, where each HW blend is part of the 91 // pipeline key, so using a known blend mode ID ensures the PaintParamsKey are also different. 92 // 93 // Lastly, for advanced blend modes that require complex shader calculations, we assume they 94 // are used rarely and with intent (i.e. unlikely to share a common shader tree with another 95 // advanced blend if we were to add branching). This keeps the amount of reachable SkSL that 96 // must be compiled for a given pipeline with advanced blends to a minimum. 97 // 98 // NOTE: Pipeline code generation depends on the fixed-function code IDs being contiguous and be 99 // defined last in the enum. They are ordered to match SkBlendMode such that: 100 // (id - kFirstFixedBlend) == SkBlendMode). 101 kFixedBlend_Clear, 102 kFixedBlend_Src, 103 kFixedBlend_Dst, 104 kFixedBlend_SrcOver, 105 kFixedBlend_DstOver, 106 kFixedBlend_SrcIn, 107 kFixedBlend_DstIn, 108 kFixedBlend_SrcOut, 109 kFixedBlend_DstOut, 110 kFixedBlend_SrcATop, 111 kFixedBlend_DstATop, 112 kFixedBlend_Xor, 113 114 kFixedBlend_Plus, // NOTE: Adds shader clamping, not compatible with GetPorterDuffConstants 115 kFixedBlend_Modulate, // NOTE: Uses color channels, incompatible with kPorterDuffBlender 116 kFixedBlend_Screen, // "" 117 118 // With support for advanced blend modes, these can also be handled by HW for the final blend. 119 kFixedBlend_Overlay, 120 kFixedBlend_Darken, 121 kFixedBlend_Lighten, 122 kFixedBlend_ColorDodge, 123 kFixedBlend_ColorBurn, 124 kFixedBlend_HardLight, 125 kFixedBlend_SoftLight, 126 kFixedBlend_Difference, 127 kFixedBlend_Exclusion, 128 kFixedBlend_Multiply, 129 130 kFixedBlend_Hue, 131 kFixedBlend_Saturation, 132 kFixedBlend_Color, 133 kFixedBlend_Luminosity, 134 135 kFirstFixedBlend = kFixedBlend_Clear, 136 kLast = kFixedBlend_Luminosity 137 }; 138 static constexpr int kBuiltInCodeSnippetIDCount = static_cast<int>(BuiltInCodeSnippetID::kLast)+1; 139 static constexpr int kFixedBlendIDOffset = 140 static_cast<int>(BuiltInCodeSnippetID::kFirstFixedBlend); 141 142 static_assert(BuiltInCodeSnippetID::kLast == BuiltInCodeSnippetID::kFixedBlend_Luminosity); 143 144 } // namespace skgpu::graphite 145 146 #endif // skgpu_graphite_BuiltInCodeSnippetID_DEFINED 147