| 1 |
/* |
| 2 |
* Copyright 2024 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_precompile_PrecompileImageFilter_DEFINED |
| 9 |
#define skgpu_graphite_precompile_PrecompileImageFilter_DEFINED |
| 10 |
|
| 11 |
#include "include/gpu/graphite/precompile/PrecompileBase.h" |
| 12 |
|
| 13 |
#include "include/core/SkBlendMode.h" |
| 14 |
#include "include/gpu/graphite/precompile/PaintOptions.h" |
| 15 |
#include "include/private/base/SkTemplates.h" |
| 16 |
|
| 17 |
namespace skgpu::graphite { |
| 18 |
|
| 19 |
class PrecompileBlender; |
| 20 |
class PrecompileColorFilter; |
| 21 |
class PrecompileImageFilterPriv; |
| 22 |
|
| 23 |
/** \class PrecompileImageFilter |
| 24 |
This class corresponds to the SkImageFilter class in the main API. |
| 25 |
*/ |
| 26 |
class SK_API PrecompileImageFilter : public PrecompileBase { |
| 27 |
public: |
| 28 |
~PrecompileImageFilter() override; |
| 29 |
|
| 30 |
// Provides access to functions that aren't part of the public API. |
| 31 |
PrecompileImageFilterPriv priv(); |
| 32 |
const PrecompileImageFilterPriv priv() const; // NOLINT(readability-const-return-type) |
| 33 |
|
| 34 |
protected: |
| 35 |
PrecompileImageFilter(SkSpan<sk_sp<PrecompileImageFilter>> inputs); |
| 36 |
|
| 37 |
private: |
| 38 |
friend class PaintOptions; // for createPipelines() access |
| 39 |
friend class PrecompileImageFilterPriv; |
| 40 |
|
| 41 |
int countInputs() const { return fInputs.count(); } |
| 42 |
|
| 43 |
const PrecompileImageFilter* getInput(int index) const { |
| 44 |
SkASSERT(index < this->countInputs()); |
| 45 |
return fInputs[index].get(); |
| 46 |
} |
| 47 |
|
| 48 |
virtual sk_sp<PrecompileColorFilter> isColorFilterNode() const { return nullptr; } |
| 49 |
|
| 50 |
sk_sp<PrecompileColorFilter> asAColorFilter() const; |
| 51 |
|
| 52 |
// The PrecompileImageFilter classes do not use the PrecompileBase::addToKey virtual since |
| 53 |
// they, in general, do not themselves contribute to a given SkPaint/Pipeline but, rather, |
| 54 |
// create separate SkPaints/Pipelines from whole cloth (in onCreatePipelines). |
| 55 |
void addToKey(const KeyContext& /* keyContext */, int /* desiredCombination */) const final { |
| 56 |
SkASSERT(false); |
| 57 |
} |
| 58 |
|
| 59 |
virtual void onCreatePipelines(const KeyContext&, |
| 60 |
const RenderPassDesc&, |
| 61 |
const PaintOptions::ProcessCombination&) const = 0; |
| 62 |
|
| 63 |
void createPipelines(const KeyContext&, |
| 64 |
const RenderPassDesc&, |
| 65 |
const PaintOptions::ProcessCombination&); |
| 66 |
|
| 67 |
skia_private::AutoSTArray<2, sk_sp<PrecompileImageFilter>> fInputs; |
| 68 |
}; |
| 69 |
|
| 70 |
//-------------------------------------------------------------------------------------------------- |
| 71 |
// This is the Precompile correlate to the SkImageFilters class' factories in the main API |
| 72 |
// |
| 73 |
// Note: In order to make precompilation analysis more tractable we don't allow options for the |
| 74 |
// internals of an PrecompileImageFilter nor in the structure of the DAG. |
| 75 |
namespace PrecompileImageFilters { |
| 76 |
|
| 77 |
// This is the Precompile correlate to SkImageFilters::Arithmetic |
| 78 |
SK_API sk_sp<PrecompileImageFilter> Arithmetic(sk_sp<PrecompileImageFilter> background, |
| 79 |
sk_sp<PrecompileImageFilter> foreground); |
| 80 |
|
| 81 |
// This is the Precompile correlate to SkImageFilters::Blend(SkBlendMode, ...) |
| 82 |
SK_API sk_sp<PrecompileImageFilter> Blend(SkBlendMode bm, |
| 83 |
sk_sp<PrecompileImageFilter> background, |
| 84 |
sk_sp<PrecompileImageFilter> foreground); |
| 85 |
|
| 86 |
// This is the Precompile correlate to SkImageFilters::Blend(sk_sp<SkBlender>, ...) |
| 87 |
SK_API sk_sp<PrecompileImageFilter> Blend(sk_sp<PrecompileBlender> blender, |
| 88 |
sk_sp<PrecompileImageFilter> background, |
| 89 |
sk_sp<PrecompileImageFilter> foreground); |
| 90 |
|
| 91 |
// This is the Precompile correlate to the two SkImageFilters::Blur factories |
| 92 |
SK_API sk_sp<PrecompileImageFilter> Blur(sk_sp<PrecompileImageFilter> input); |
| 93 |
|
| 94 |
// This is the Precompile correlate to SkImageFilters::ColorFilter. |
| 95 |
SK_API sk_sp<PrecompileImageFilter> ColorFilter(sk_sp<PrecompileColorFilter> colorFilter, |
| 96 |
sk_sp<PrecompileImageFilter> input); |
| 97 |
|
| 98 |
// This is the Precompile correlate to SkImageFilters::DisplacementMap |
| 99 |
SK_API sk_sp<PrecompileImageFilter> DisplacementMap(sk_sp<PrecompileImageFilter> input); |
| 100 |
|
| 101 |
// This is the Precompile correlate to all of SkImageFilters:: |
| 102 |
// DistantLitDiffuse, PointLitDiffuse, SpotLitDiffuse |
| 103 |
// DistantLitSpecular, PointLitSpecular, SpotLitSpecular |
| 104 |
SK_API sk_sp<PrecompileImageFilter> Lighting(sk_sp<PrecompileImageFilter> input); |
| 105 |
|
| 106 |
// This is the Precompile correlate to SkImageFilters::MatrixConvolution |
| 107 |
SK_API sk_sp<PrecompileImageFilter> MatrixConvolution(sk_sp<PrecompileImageFilter> input); |
| 108 |
|
| 109 |
// This is the Precompile correlate to SkImageFilters::Erode and SkImageFilters::Dilate |
| 110 |
SK_API sk_sp<PrecompileImageFilter> Morphology(sk_sp<PrecompileImageFilter> input); |
| 111 |
|
| 112 |
} // namespace PrecompileImageFilters |
| 113 |
|
| 114 |
} // namespace skgpu::graphite |
| 115 |
|
| 116 |
#endif // skgpu_graphite_precompile_PrecompileImageFilter_DEFINED |