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_PaintParams_DEFINED 9 #define skgpu_PaintParams_DEFINED 10 11 #include "include/core/SkColor.h" 12 #include "include/core/SkPaint.h" 13 14 enum class SkBackend : uint8_t; 15 class SkPaintParamsKeyBuilder; 16 class SkShader; 17 class SkShaderCodeDictionary; 18 class SkUniformBlock; 19 20 namespace skgpu { 21 22 // TBD: If occlusion culling is eliminated as a phase, we can easily move the paint conversion 23 // back to Device when the command is recorded (similar to SkPaint -> GrPaint), and then 24 // PaintParams is not required as an intermediate representation. 25 // NOTE: Only represents the shading state of an SkPaint. Style and complex effects (mask filters, 26 // image filters, path effects) must be handled higher up. AA is not tracked since everything is 27 // assumed to be anti-aliased. 28 class PaintParams { 29 public: 30 PaintParams(const SkColor4f& color, sk_sp<SkBlender>, sk_sp<SkShader>); 31 explicit PaintParams(const SkPaint&); 32 33 PaintParams(const PaintParams&); 34 ~PaintParams(); 35 36 PaintParams& operator=(const PaintParams&); 37 color()38 SkColor4f color() const { return fColor; } 39 40 std::optional<SkBlendMode> asBlendMode() const; blender()41 SkBlender* blender() const { return fBlender.get(); } 42 sk_sp<SkBlender> refBlender() const; 43 shader()44 SkShader* shader() const { return fShader.get(); } 45 sk_sp<SkShader> refShader() const; 46 47 void toKey(SkShaderCodeDictionary*, 48 SkBackend, 49 SkPaintParamsKeyBuilder*, 50 SkUniformBlock*) const; 51 52 private: 53 SkColor4f fColor; 54 sk_sp<SkBlender> fBlender; // A nullptr here means SrcOver blending 55 sk_sp<SkShader> fShader; // For now only use SkShader::asAGradient() when converting to GPU 56 // TODO: Will also store ColorFilter, dither, and any extra shader from an 57 // active clipShader(). 58 }; 59 60 } // namespace skgpu 61 62 #endif // skgpu_PaintParams_DEFINED 63