1 /* 2 * Copyright 2020 Google Inc. 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 SkSVGFilterContext_DEFINED 9 #define SkSVGFilterContext_DEFINED 10 11 #include "include/core/SkRect.h" 12 #include "include/core/SkRefCnt.h" 13 #include "include/core/SkString.h" 14 #include "include/private/SkTHash.h" 15 #include "modules/svg/include/SkSVGTypes.h" 16 17 class SkImageFilter; 18 class SkSVGFeInputType; 19 class SkSVGRenderContext; 20 21 class SkSVGFilterContext { 22 public: SkSVGFilterContext(const SkRect & filterEffectsRegion,const SkSVGObjectBoundingBoxUnits & primitiveUnits)23 SkSVGFilterContext(const SkRect& filterEffectsRegion, 24 const SkSVGObjectBoundingBoxUnits& primitiveUnits) 25 : fFilterEffectsRegion(filterEffectsRegion) 26 , fPrimitiveUnits(primitiveUnits) 27 , fPreviousResult({nullptr, filterEffectsRegion, SkSVGColorspace::kSRGB}) {} 28 filterEffectsRegion()29 const SkRect& filterEffectsRegion() const { return fFilterEffectsRegion; } 30 31 const SkRect& filterPrimitiveSubregion(const SkSVGFeInputType&) const; 32 primitiveUnits()33 const SkSVGObjectBoundingBoxUnits& primitiveUnits() const { return fPrimitiveUnits; } 34 35 void registerResult(const SkSVGStringType&, const sk_sp<SkImageFilter>&, const SkRect&, SkSVGColorspace); 36 37 void setPreviousResult(const sk_sp<SkImageFilter>&, const SkRect&, SkSVGColorspace); 38 39 bool previousResultIsSourceGraphic() const; 40 41 SkSVGColorspace resolveInputColorspace(const SkSVGRenderContext&, 42 const SkSVGFeInputType&) const; 43 44 sk_sp<SkImageFilter> resolveInput(const SkSVGRenderContext&, const SkSVGFeInputType&) const; 45 46 sk_sp<SkImageFilter> resolveInput(const SkSVGRenderContext&, const SkSVGFeInputType&, SkSVGColorspace) const; 47 48 private: 49 struct Result { 50 sk_sp<SkImageFilter> fImageFilter; 51 SkRect fFilterSubregion; 52 SkSVGColorspace fColorspace; 53 }; 54 55 const Result* findResultById(const SkSVGStringType&) const; 56 57 std::tuple<sk_sp<SkImageFilter>, SkSVGColorspace> getInput(const SkSVGRenderContext&, 58 const SkSVGFeInputType&) const; 59 60 SkRect fFilterEffectsRegion; 61 62 SkSVGObjectBoundingBoxUnits fPrimitiveUnits; 63 64 SkTHashMap<SkSVGStringType, Result> fResults; 65 66 Result fPreviousResult; 67 }; 68 69 #endif // SkSVGFilterContext_DEFINED 70