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 kCubicImageShader, 49 kHWImageShader, 50 kYUVImageShader, 51 kCubicYUVImageShader, 52 kHWYUVImageShader, 53 kHWYUVNoSwizzleImageShader, 54 kCoordClampShader, 55 kDitherShader, 56 kPerlinNoiseShader, 57 58 // SkColorFilter code snippets 59 kMatrixColorFilter, 60 kTableColorFilter, 61 kGaussianColorFilter, 62 kColorSpaceXformColorFilter, 63 kPremulAlphaColorFilter, 64 65 // Emits special variable holding the primitiveColor emitted by a RenderStep 66 kPrimitiveColor, 67 68 // Analytic clip for circular roundrect and AA rect shapes 69 kCircularRRectClip, 70 71 kCompose, // compose 2 children together: outer_1(inner_0(...)) 72 kBlendCompose, // compose 3 children together: outer_2(inner_0(...), inner_1(...)) 73 74 // SkBlender code snippets 75 kPorterDuffBlender, // Can handle all GetPorterDuffBlendConstants() modes 76 kHSLCBlender, // kHue,kSaturation,kLuminosity, and kColor modes 77 // NOTE: We could offer an in-shader consolidation for overlay+hardlight, and darken+lighten 78 // but for now, those will map to the FixedBlends. 79 80 // Fixed blend modes hard code a specific blend function into the shader tree. This can be 81 // valuable when an internal effect is known to always do a certain blend and we want to 82 // benefit from inlining constants. It is also important for being able to convert the final 83 // blend of the SkPaint into fixed function HW blending, where each HW blend is part of the 84 // pipeline key, so using a known blend mode ID ensures the PaintParamsKey are also different. 85 // 86 // Lastly, for advanced blend modes that require complex shader calculations, we assume they 87 // are used rarely and with intent (i.e. unlikely to share a common shader tree with another 88 // advanced blend if we were to add branching). This keeps the amount of reachable SkSL that 89 // must be compiled for a given pipeline with advanced blends to a minimum. 90 // 91 // NOTE: Pipeline code generation depends on the fixed-function code IDs being contiguous and be 92 // defined last in the enum. They are ordered to match SkBlendMode such that: 93 // (id - kFirstFixedBlend) == SkBlendMode). 94 kFixedBlend_Clear, 95 kFixedBlend_Src, 96 kFixedBlend_Dst, 97 kFixedBlend_SrcOver, 98 kFixedBlend_DstOver, 99 kFixedBlend_SrcIn, 100 kFixedBlend_DstIn, 101 kFixedBlend_SrcOut, 102 kFixedBlend_DstOut, 103 kFixedBlend_SrcATop, 104 kFixedBlend_DstATop, 105 kFixedBlend_Xor, 106 107 kFixedBlend_Plus, // NOTE: Adds shader clamping, not compatible with GetPorterDuffConstants 108 kFixedBlend_Modulate, // NOTE: Uses color channels, incompatible with kPorterDuffBlender 109 kFixedBlend_Screen, // "" 110 111 // With support for advanced blend modes, these can also be handled by HW for the final blend. 112 kFixedBlend_Overlay, 113 kFixedBlend_Darken, 114 kFixedBlend_Lighten, 115 kFixedBlend_ColorDodge, 116 kFixedBlend_ColorBurn, 117 kFixedBlend_HardLight, 118 kFixedBlend_SoftLight, 119 kFixedBlend_Difference, 120 kFixedBlend_Exclusion, 121 kFixedBlend_Multiply, 122 123 kFixedBlend_Hue, 124 kFixedBlend_Saturation, 125 kFixedBlend_Color, 126 kFixedBlend_Luminosity, 127 128 kFirstFixedBlend = kFixedBlend_Clear, 129 kLast = kFixedBlend_Luminosity 130 }; 131 static constexpr int kBuiltInCodeSnippetIDCount = static_cast<int>(BuiltInCodeSnippetID::kLast)+1; 132 static constexpr int kFixedBlendIDOffset = 133 static_cast<int>(BuiltInCodeSnippetID::kFirstFixedBlend); 134 135 static_assert(BuiltInCodeSnippetID::kLast == BuiltInCodeSnippetID::kFixedBlend_Luminosity); 136 137 } // namespace skgpu::graphite 138 139 #endif // skgpu_graphite_BuiltInCodeSnippetID_DEFINED 140