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_KeyContext_DEFINED 9 #define skgpu_graphite_KeyContext_DEFINED 10 11 #include "include/core/SkImageInfo.h" 12 #include "include/core/SkM44.h" 13 #include "include/core/SkMatrix.h" 14 15 namespace skgpu::graphite { 16 17 class Recorder; 18 class RuntimeEffectDictionary; 19 class ShaderCodeDictionary; 20 21 // The key context must always be able to provide a valid ShaderCodeDictionary and 22 // SkRuntimeEffectDictionary. Depending on the calling context it can also supply a 23 // backend-specific resource providing object (e.g., a Recorder). 24 class KeyContext { 25 public: 26 // Constructor for the pre-compile code path (i.e., no Recorder) KeyContext(ShaderCodeDictionary * dict,RuntimeEffectDictionary * rtEffectDict,const SkColorInfo & dstColorInfo)27 KeyContext(ShaderCodeDictionary* dict, 28 RuntimeEffectDictionary* rtEffectDict, 29 const SkColorInfo& dstColorInfo) 30 : fDictionary(dict) 31 , fRTEffectDict(rtEffectDict) 32 , fDstColorInfo(dstColorInfo) { 33 } 34 35 // Constructor for the ExtractPaintData code path (i.e., with a Recorder) 36 KeyContext(Recorder*, const SkM44& local2Dev, const SkColorInfo&); 37 38 KeyContext(const KeyContext&); 39 recorder()40 Recorder* recorder() const { return fRecorder; } 41 local2Dev()42 const SkM44& local2Dev() const { return fLocal2Dev; } localMatrix()43 const SkMatrix* localMatrix() const { return fLocalMatrix; } 44 dict()45 ShaderCodeDictionary* dict() const { return fDictionary; } rtEffectDict()46 RuntimeEffectDictionary* rtEffectDict() const { return fRTEffectDict; } 47 dstColorInfo()48 const SkColorInfo& dstColorInfo() const { return fDstColorInfo; } 49 50 protected: 51 Recorder* fRecorder = nullptr; 52 SkM44 fLocal2Dev; 53 SkMatrix* fLocalMatrix = nullptr; 54 ShaderCodeDictionary* fDictionary; 55 RuntimeEffectDictionary* fRTEffectDict; 56 SkColorInfo fDstColorInfo; 57 }; 58 59 class KeyContextWithLocalMatrix : public KeyContext { 60 public: KeyContextWithLocalMatrix(const KeyContext & other,const SkMatrix & childLM)61 KeyContextWithLocalMatrix(const KeyContext& other, const SkMatrix& childLM) 62 : KeyContext(other) { 63 if (fLocalMatrix) { 64 fStorage = SkMatrix::Concat(childLM, *fLocalMatrix); 65 } else { 66 fStorage = childLM; 67 } 68 69 fLocalMatrix = &fStorage; 70 } 71 72 private: 73 KeyContextWithLocalMatrix(const KeyContextWithLocalMatrix&) = delete; 74 KeyContextWithLocalMatrix& operator=(const KeyContextWithLocalMatrix&) = delete; 75 76 SkMatrix fStorage; 77 }; 78 79 } // namespace skgpu::graphite 80 81 #endif // skgpu_graphite_KeyContext_DEFINED 82